Replace Text in file Using Shell Script
What is the easiest way to replace text in a text file using Shell Script instead of going into vi editor to do that?
I am trying to replace all "1234" to "4321" in a text file.
Linux
What is the easiest way to replace text in a text file using Shell Script instead of going into vi editor to do that?
I am trying to replace all "1234" to "4321" in a text file.
by cpfeiffe
Use:
sed 's/1234/4321/g' file > file.new
Sed replaces text strings (and does some other things). Enclosed in '' is your sed argument. You are saying s(ubstitute) 1234 with 4321 g(lobally). Without the g it will simply replace the first occurrance. You can't replace it in the original file so you need to redirect the output to a new file, but you can then rename the new file 'mv file.new file' to complete the task.
Good luck.
by working it
This discussion is closed to new replies.
Sort by Trending