New here? Register and read our Community Rules. Accounts are approved by hand.
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 ... ![]()
0

Comments
sed -i 's/GOOGLE/DUCKDUCKGO/' text.txtwill only replace the first "GOOGLE" word
Second answer.
sed -i '19s/\/var\/www\/html\/web/\/home\/fahad\/html\/web/' text.txtIt 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.