Get everything in the file after the grep'd line

Yesterday a situation arose when someone needed me to select the end of the file, indicated as everything after a certain line (for the sake of the argument, "FOO"). I needed to do this immediately, so I went with an option that I knew would work, and ignored the "Right Way" or "Best Way", and went with the following:

grep -n FOO FILE.TXT | cut -f1 -d":" | xargs -I{} tail -n +{} FILE.TXT > NEWFILE.TXT 

What bothered me was the use of xargs for a singleton value. I thought I could roll my Google-Fu on this, but I was interested to know what things people in SO-land came up with for this situation.

+6
source share
3 answers
 sed -n '/re/,$p' file 

what happens to me right away.

+15
source

Do you just consider using the grep argument '-after-context'?

Something like this, this should do the trick with a big enough number to print the end of the file:

 grep --after-context=999999 -n FOO FILE.TXT > NEWFILE.TXT 
+10
source

As with the geekosaur answer above, but this option excludes rather than includes the corresponding line:

 sed '1,/regex/d' myfile 

Found this one here by trying the option above.

+1
source

Source: https://habr.com/ru/post/887863/


All Articles