Tuesday, June 26, 2012

Recent nice sed commands

Here are two nice sed calls that I did today:

To delete 6 lines out of every file that has a particular line in it:

grep -n "The number of passes was" | xargs -L1 -t sed -i -e '/The number of passes was/,+6d'

To delete all lines containing a match out of every file:

grep -n "$start_" | xargs -L1 -t sed -i -e '/\$start_/,+1d'

the -t in xargs is just to echo which files were altered to the screen, the -i in sed is modify in place (very handy), the +1 before the d in the second command was probably unneccesary.