Delete all lines before first occurrence of specific string in file

Viewed 11634

Basically I have a file like:

junk
morejunk
somestring
bats
car
somestring
bats
car
somestring
bats
car

and I want to remove all of the junk before the first occurrence of somestring so the file looks like

somestring
bats
car
somestring
bats
car
somestring
bats
car

I followed the advice from this question to use sed -i '0,/somestring/,d' file.txt but it deletes the line with the first occurrence of somestring, when I want to keep that line as the first line.

5 Answers
Related