Thursday, July 3, 2008

matching multiple lines in Unix

This will pull out the multiple lines from the log, where the first line has XXX and the last line has YYY:


perl -n -e "print if (/XXX/ ... /YYY/)" file


To substitute string "country_bumpkin" for "country" in a whole bunch of files:


perl -p -i -e "s/country/country_bumpkin/g" files

No comments: