Skip to content
Tags

,

Bash tips & tricks

by admin on June 11th, 2009

I know that bash is not really a scripting language (I like perl ) but there are times when you just want to do things on a single command line.

So, if you want for example drop some databases from a folder list:

ls /var/lib/mysql | grep dbmatch* | while read i; do echo “drop database $i”; done | mysql

Or, if you want to change same content on multiple files:

cd folder ; grep “oldvalue” * -l | while read f; do cat $f | sed s/oldvalue/newvalue/ > /tmp/x; cat /tmp/x > $f; done

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS