2

I want to search and replace string located in a several files via bash console.

Here is the command I use to find a string in a file:

grep "string" * -r

so the above is for searching, now I need a command to replace the string.

Is that even possible?

Cyclone
  • 14,839
  • 23
  • 82
  • 114
  • 1
    See http://stackoverflow.com/questions/4996460/how-do-i-replace-the-word-hello-with-goodbye-in-every-file-in-this-directory/4996483 – Antti Jan 17 '12 at 22:09

1 Answers1

4

http://www.grymoire.com/Unix/Sed.html

It's cranky and difficult, but it's one way to do it.

Here's an example:

sed -i 's/ugly/beautiful/g' /home/bruno/old-friends/sue.txt

This replaces ugly with beautiful in sue.txt.

Almo
  • 15,538
  • 13
  • 67
  • 95