Results 1 to 3 of 3
I want to replace a word in a text file (file.txt) using shell script. The contents of the file are:
file.txt
--------------
line one goes here
line two is here
...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-21-2010 #1Just Joined!
- Join Date
- Oct 2010
- Posts
- 5
Edit a file using shell script
I want to replace a word in a text file (file.txt) using shell script. The contents of the file are:
file.txt
--------------
line one goes here
line two is here
and so on........
I tried following command for replacing a text:
It did replace the text but not in the file. I got the replaced text as an output on the console as following.Code:sed -e 's/here/dear/g' file.txt
I want to replace the text in the file. How do I do that?Code:line one goes dear line two is dear and so on........
- 10-21-2010 #2Linux Newbie
- Join Date
- Apr 2007
- Posts
- 119
You have to redirect the output to a file and then save that file as the old one.
Code:sed -e 's\here\dear\g' file.txt > filenew.txt mv filenew.txt file.txt
- 10-21-2010 #3
sed -i also works, but keep in mind, that this is not portable between different unixes
You must always face the curtain with a bow.


Reply With Quote
