ACPI administration advocacy advocacy advocacy opinion alsa apache apple apt aptitude audio authentication awk bash BIOS boot 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 linux locale lockin longlines microsoft minitab 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 statistics subversion sudo svk swap t23 t43 terminal text thinkpad thunderbird time timezone ubuntu upgrade users versioncontrol video windows wine wordpress wordprocessing X40 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.
Red Hat Certified Technician & Engineer (RHCT and RHCE) Training Guide and Administrator's Reference