Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I extract all the contents of a file which comes after a given line ? The line can be matched by exact contents or regular expression.

share|improve this question
up vote 1 down vote accepted
awk 'BEGIN { found=0; } /RE GOES HERE/ { found = 1; } found { print; }' $filename

Avoids multiple file traversals, so should (possibly) perform better for large files where the match is towards the end of the file.

share|improve this answer
tail -n +`egrep -n "pattern" "file_to_search.txt" | cut -d ":" -f 2 | tail -n 1` "file_to_tail.txt"
share|improve this answer
The section in grey (from egrep -n "pattern" to tail -n 1) is enclosed in backticks. – gvk Dec 16 '09 at 8:40
Thanks for the answer. I assume you mean cut -d ":" -f 1 to get the first field - the line number. – Robert Munteanu Dec 16 '09 at 9:07
Second field actually. The first field would be the matching file name :) – gvk Dec 16 '09 at 9:08
Hm, somehow that does not work for me. Using grep 2.5.4 on OpenSUSE 11.2 . But I get the drift :-) – Robert Munteanu Dec 16 '09 at 10:31

This simple awk program should do the job:

awk '/pattern/,""' filename
share|improve this answer

And also:

sed -n '/pattern/,$ p' filename
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.