Ubuntu – cat command replace text Linux shell script

14.04cat

I have shell script file. In there is code like: <tag>port:8080</tag>.
I want to replace this code line with another code line: <tag>port:3128</tag>.
How do I do that?
I used cat, but it removed all the code lines and only added this code line..can anyone tell me how to replace the text in shell scripting ?
This is how I tryed it:

cat <<EOF > /home/samples/pom.xml
<tag>port:3128</tag>
EOF

Best Answer

Assuming your file is YOURFILE in the current directory, try sed -i 's/8080/3128/g' YOURFILE

This will replace all occurences of 8080 with 3128.

Related Question