Sonntag, 10. April 2011

Shell 005: Redirect Part of a File

Suppose a file contains data starting from a given keyword (the content above the keyword is considered not relevant). If only the content from after the keyword is to be redirected to a new file (in a batch), this can be done using sed.
for i in file-*.logdo    sed -n '0,/DONE/!p' $i >${i/file/new}done

"!" tells it to ignore everything from the start of the file "0" to the first line containing the keyword "/DONE/", then p makes it print the rest, with a shell redirection of the output to a new file.
Regards to David the H. at LinuxQuestions for pointing this out to me.