I have a file, with a "KEYWORD" on line number n. How can I print all lines starting from line n+1 until the end?
For example, here I would liek to pro=int only lines DDD and EEE
AAA
BBB
CCC
KEYWORD
DDD
EEE
I have a file, with a "KEYWORD" on line number n. How can I print all lines starting from line n+1 until the end?
For example, here I would liek to pro=int only lines DDD and EEE
AAA
BBB
CCC
KEYWORD
DDD
EEE
You can do this with sed
:
sed '1,/^KEYWORD$/d'
This will delete (omit) all lines from the beginning of the stream until "KEYWORD", inclusive.
sed '1,/KEYWORD/d'
, instead. The context was a little different, but using 0,
would print the contents of the entire file, no matter what KEYWORD was.
– juniper-
Mar 16 '15 at 08:08
Use sed, printing from the KEYWORD match to the end of the file, then using tail to remove the KEYWORD line.
sed -n '/KEYWORD/,$p' file | tail -1
An alternative might be grep
in combination with the -A
flag, e.g.
grep -A10000 KEYWORD file
Where 10000
is just a big number to denoted the amount of lines until the end of the file, which for your practical daily use should be enough.
Otherwise you could use the amount of lines in the file as parameter like this
grep -A$(wc -l file | cut -d' ' -f1) KEYWORD file
But that is most likely overkill (and not easier to remember than the given sed
alternative)