sed, grep and updating a static website.

so one of the offices at the company recently moved from one city to another. they are in the process of migrating the public website from an old static page to a new page using wordpress. if the new site was online, changing a footer with the office address wouldn’t be a problem.  well the new shiny office doesn’t come with the new shiny website.  had to do some cli kung-fu to get the address changed.

so i figured since line of the address in html was on a separate line the best thing was to grep for the string, then use sed to replace it, it’s not elegant but it worked.

first thing we do, we back up our crap in case i totally screw it up. then once my backups are done i run the first part of the string:

grep -lr -e ‘123 Old Street Location, Floor 3’ * | xargs sed -i ‘s/123 Old Street Location, Floor 3/555 New Street Location Suite 4/g’

then let’s do the new city and zip

grep -lr -e ‘Cambridge, MA 02139 USA’ * | xargs sed -i ‘s/Cambridge, MA 02139 USA/Boston, MA 02111 USA/g’ 

this got the job done and quickly since the problem was sitting around for a little while and no one seemed to notice.

Tagged , , ,

One thought on “sed, grep and updating a static website.

  1. dialt0ne says:

    Looking at using the -Z option with grep and the -0 option for xargs to handle files with weird characters in their names.

Leave a Reply

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

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

Google photo

You are commenting using your Google 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

%d bloggers like this: