I have a file which is made up of several lines of text:
The first line
The second line
The third line
The fourth line
I have a string which is one of the lines: The second line
I want to delete the string and all lines after it in the file, so it will delete The third line
and The fourth line
in addition to the string. The file would become:
The first line
I've searched for a solution on google, and it seems that I should use sed
. Something like:
sed 'linenum,$d' file
But how to find the line number of the string? Or, how else should I do it?