delete top lines of a text file until a word is met
Hi,
I need to chop of the top 30ish lines of several log files until a line starting with "Initialization completed." The trouble is that it's not always the same amount of lines that need to be deleted, and they don't always contain the same information, which is why I would need to delete everything prior to the line starting with "Initialization completed." Right now I have a little script I wrote based on looping each file through several "grep -v" commands with each known pattern of lines I want to ignore, but it is tedious and I have to inspect each file afterwards to make sure nothing is left from above "Initialization completed." Any tips or ideas would be appreciated. Thanks! |
Hi,
Is this what you are looking for: Code:
sed '1,/^Initialization completed/d' infile |
Hi again,
Not sure if you want to delete the Initialization completed line or not. If not: Code:
sed '1,/^Initialization completed/c Initialization completed' infile |
Just on top what druuna said:
If you want to make permanent changes to the file, you can either: a) use the -i flag (the existing content will be overwritten): Code:
sed -i '1,/^Initialization completed/c Initialization completed' infile Code:
sed -i.bk '1,/^Initialization completed/c Initialization completed' infile b) redirect the output to a new file Code:
sed '1,/^Initialization completed/c Initialization completed' infile > newfile |
All times are GMT -5. The time now is 09:03 PM. |