Archive for June, 2009

sed: Remove lines that match a pattern

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

sed  '/mypattern/d' file


Deletes all files that contain the regular expression “mypattern”.

In-place replacement:

sed --in-place '/mypattern/d' file1


sed also supports making backups with e.g. –in-place=.backup .

No Comments

Jake

Did I mention Jake came out of the closet?

No Comments

Shutdown when idle

Maybe you want the computer to shutdown after it has done its task. This shuts down your Linux box when the load goes down to zero. Kind of like the “Speed” movies.

while ! cat /proc/loadavg |cut -f2 -d ' '|grep '0\.00'; do sleep 10m; done && poweroff

Alternatively:

while ps 12345; do sleep 10m; done && poweroff

No Comments