Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a dev copy of a website set up that has quite a few hardcoded references to its live counterpart.

I would like to replace all occurrences of "www." with "dev." in all files.

I think I can use a combination of grep + sed, but I'm not sure how.

share|improve this question
Lol it's not programing question. It's basic power user skill. – Maciek Sawicki Mar 8 '10 at 15:52
@Maciek: I can buy that! – Josh K Mar 8 '10 at 17:56
up vote 2 down vote accepted

first try to used sed on one file its sed 's/foo/bar/g' for replacing foo with bar. Then instead of grep i suggest find. Use it to find all files that need changes (*.php, *.html, etc...). Then find have -exec option.

Please make backup of Your project before You start.

share|improve this answer
Use sed 's/foo/bar/g' for a global replace. – eleven81 Mar 8 '10 at 16:08
Thanks. You are 100% right. with out it in only replace only first instance in a line. I edited my answerer. – Maciek Sawicki Mar 8 '10 at 16:25
I'm trying something like this with no success so far: find . -name '*.html' -exec sed 's/www/dev/g' {} \; – user30063 Mar 9 '10 at 15:12
FYI I ended up using: find . -name "*.php" -print | xargs sed -i 's/www\./dev\./g' – user30063 Mar 9 '10 at 18:55

You must log in to answer this question.