ACPI administration advocacy advocacy advocacy opinion alsa apache apple audio authentication awk bash business cache calendar censorship commandline cron database debian desktop development disk dvd economics emacs email europe exim files firefox firewall flash foss freedom ftp fun git grub hardware hardware html images installation ipod kde kernel keyboard knoppix laptop latex locale lockin longlines mplayer multimedia mysql network nfs openbox openoffice opinion opinion partition pdf perl php politics postgresql printing privacy rant rxvt script scripting scsi security sed server shell siteadmin sitenews sitesoftware skype skype slackware sound spam ssh subversion sudo svk swap t23 t43 terminal text thinkpad thunderbird time timezone ubuntu users versioncontrol video windows wine wordpress wordprocessing xwindows xwindows youtube
I recently had a series of files that contained the string '-1'. I wanted to remove all the lines that contained that string from all files in a directory tree. Using sed or awk seemed to be the obvious thing to do:
awk '!/-1/ {print $0 }' filename
Prints the file to STDOUT minus the lines containing '-1'. This does the same with sed:
sed -e '/-1/d' filename
However what I wanted to do was to modify the files "in place", to do this in awk seemed a bit convoluted, but in sed it's easy:
sed -i -e '/-1/d' `find path/to/directory`
Here, find walks a directory tree and passes all the files to sed that then removes the line containing '-1' rewriting the file.