CLI onliners: Changing my email address in multiple files

March 7, 2011

Just sharing a one line I’ve used to change the domain for my email address throughout the various source code files I’ve contributed to at work.

First of all I get a list of all the files which match my old email address, which I then strip of svn specific files and binaries.

grep -HR "<david.morris@greenacre.no-ip.com>" * | grep -v Binary | grep -v .svn

Then for every result I grab the filename with

cut -f1 -d:

For every filename I use sed to replace the email domain, which I then redirect to a temp file.

sed 's/greenacre.no-ip.com/code-fish.co.uk/g' "$file" > "$file".new

Then we need to move the new file over the old file with

mv "$file".new "$file"

So all combined and in a for loop it looks like

for file in `grep -HR "<david.morris@greenacre.no-ip.com>" * | grep -v Binary |
grep -v .svn | cut -f1 -d:`; do sed 's/greenacre.no-ip.com/code-fish.co.uk/g'
"$file" > "$file".new; mv "$file".new "$file"; done
sussex@mailman.lug.org.uk
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.