HowTo/GetSpecificLinesOfTextFiles

From S23Wiki
Jump to: navigation, search

You may ask yourself "Ok,i know 'tail' and 'head' to show beginning and end of a textfile, but how to get certain lines out of the middle?"

The answer: combine them with a "pipe" like this

Examples:


Line 1:     head -1 text.txt
Line 2:     head -2 text.txt | tail -1
Line 4:     head -4 text.txt | tail -1
Line 3 & 4: head -4 text.txt | tail -2

Line 5 to 7: head -7 test.txt | tail -3

Line 4 to 10: head -10 test.txt | tail -7

etc ...

---

NAME
       head - output the first part of files

SYNOPSIS
       head [OPTION]... [FILE]...

-n, --lines=[-]N
              print  the  first  N  lines instead of the first 10; with the leading `-', print all but the
              last N lines of each file

---

NAME
       tail - output the last part of files

SYNOPSIS
       tail [OPTION]... [FILE]...

-n, --lines=N
              output the last N lines, instead of the last 10


--> ManPages