2

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.

2
  • 3
    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
2

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.

4
  • 2
    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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy