ACPI administration advocacy advocacy advocacy opinion alsa amarok apache apple apt aptitude audio audo authentication automount avi awk bash BIOS boot business cache calendar calibre censorship commandline computerscience console cron cut database date debian degree design desktop development disk dpkg dvd economics education emacs email europe exim faad ffmpeg files firefox firewall flash foss freedom ftp fun fuse git gnumeric grep growisofs grub gtkpod hardware hardware html idiocy images installation ip iphone ipod iptables iso itunes ivman kde kernel keyboard knoppix lame laptop latex linux locale lockin longlines m4a microsoft mimetypes minitab mount mp3 mp4 mplayer multimedia music mysql network nfs nfs4 nmap openbox openoffice opinion opinion partition pdf perl php politics postgresql printing privacy programming rant remote rhythmbox rss rsync rxvt scp script scripting scsi security sed server shell siteadmin sitenews sitesoftware skype skype slackware sound sox spam spreadsheet ssh statistics subversion sudo svk swap t23 t43 terminal text thinkpad thunderbird time timezone ubuntu udev upgrade usb usbmount users uuid versioncontrol vfat video vnc 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.