SED useful commands

Valic —  February 5, 2013 — Leave a comment

1. How to remove lines ending with ‘baddump’ from a text file:

You’ve got a file with a bunch of lines end with “baddump”  and you need those lines to be removed completely without leaving any blank lines behind? This is the command to do it:

sed -i '/baddump$/d' file

2. You have text files with tons of empty lines and you want to get rid of those in one second?

sed '/^$/d' file > new_file

You may have multiple html files to correct at the same time.You can do that with foreach command:

foreach file (*html)
sed '/^$/d' $file > new_files Continue Reading...

Page 1 of 11