New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
Replace strings from a file
Let, I have a file (text.txt) where i want to replace specific lines "GOOGLE" word to "DUCKDUCKGO".
sed -i 's/GOOGLE/DUCKDUCKGO/g' text.txt
Above command will change/replace every line. What can i do ?
Also i want a little bit different one,
I have a line "/var/www/html/web" which i want to be replaced with "/home/fahad/html/web" from specific line maybe 19 .... What can i do ? Please help me on this ...
Comments
sed -i 's/GOOGLE/DUCKDUCKGO/' text.txt
will only replace the first "GOOGLE" word
Second answer.
sed -i '19s/\/var\/www\/html\/web/\/home\/fahad\/html\/web/' text.txt
It will replace /var/www/html/web with /home/fahad/html/web in line 19. If you are not sure, remove option -i so it will display the result. After you sure you can add -i again.
Thanks a lot. It worked.