how to replace text in txt file using unix command
I have a thegeekstuff.txt file as the following
nstruction Guides 1. Linux-Unix Sysadmin, Linux-Unix Scripting etc. 2. Databases - Oracle, mySQL etc. 3. Security (Firewall, Network, Online Security etc) 4. Storage in Linux-Unix 5. Productivity (Too many technologies to explore, not much time available) # Additional FAQS 6. Windows- Sysadmin, reboot etc. I want to replace Linux-Unix with "Linux Unix". But it didn't work. lwang@california:~$ sed 's/Linux-Unix/Linux Unix/g' thegeekstuff.txt nstruction Guides 1. Linux Sysadmin, Linux Scripting etc. 2. Databases - Oracle, mySQL etc. 3. Security (Firewall, Network, Online Security etc) 4. Storage in Linux 5. Productivity (Too many technologies to explore, not much time available) # Additional FAQS I tried "sed 's/Linux-Unix/Linux\sUnix/g'", it didn't work either. |
Interesting, it worked for me...
What version of sed? Code:
sed --version |
Try this:
Quote:
So you have to use escaping character(\) before the space in order to skip it. Using perl: Quote:
|
Thanks for the replay.
lwang@california:~$ sed --version GNU sed version 4.1.5 I tried the following, it looked right on the console print out, but the thegeekstuff.txt file wasn't changed. lwang@california:~$ sed 's/Linux-Unix/Linux\ Unix/g' thegeekstuff.txt truction Guides 1. Linux Unix Sysadmin, Linux Unix Scripting etc. 2. Databases - Oracle, mySQL etc. 3. Security (Firewall, Network, Online Security etc) 4. Storage in Linux Unix 5. Productivity (Too many technologies to explore, not much time available) # Additional FAQS 6. Windows- Sysadmin, reboot etc. so I did 1. "sed 's/Linux-Unix/Linux\ Unix/g' thegeekstuff.txt > newgeek", newgeek has what I wanted. 2. I added "-i" so that thegeekstuff.txt was changed in place. "sed -i 's/Linux-Unix/Linux\ Unix/g" $ perl -pi -w -e "s/Linux-Unix/Linux\ Unix/g" thegeekstuff.txt worked for me as well. |
All times are GMT -5. The time now is 06:44 PM. |