|
#1
| |||
| |||
| Search and replace using bash script? Hello, I'm kind of a bash newbie, so I'm wondering if anyone could help me out on this. Say I have a txt file saved somewhere, and I would like to replace certain words within that file (using the terminal) and then copy the file with the replaced words somewhere else. Is this possible? Thank you for your help! |
|
#2
| ||||
| ||||
| The 'sed' command will do the trick. Say for example you have a text file "input.txt" and you want to replace every occurance of the word "Hello" with "Goodbye". The output will be in "output.txt". In the terminal, you can do: Code: sed 's/Hello/Goodbye/g' input.txt > output.txt Check out the man page (in the terminal issue the command "man sed' without the quotes), or do a web search for "sed" for more information. Last edited by macbri; July 25th, 2007 at 12:55 PM. |
|
#3
| |||
| |||
| Ha! Works perfectly. Thank you so much for your help. |