Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replacing words in txt file ?

Status
Not open for further replies.

haneo

Programmer
Jan 2, 2002
274
0
0
CA
i want to replace the expression "/usr/local/mrtg-2/bin//mrtg" with this "/usr/bin/mrtg"

here is a part of my file:

/usr/local/mrtg-2/bin//mrtg /home/mrtg//ens1/ens1.cfg > /dev/null 2>&1
/usr/local/mrtg-2/bin//mrtg /home/mrtg//ens2/ens2.cfg > /dev/null 2>&1
/usr/local/mrtg-2/bin//mrtg /home/mrtg//ens3/ens3.cfg > /dev/null 2>&1

who can i do it ?

Thanks
 
Try using sed. (the Stream Editor). This works really well, and is reasonably easy to use. (man sed).

Good Luck!
 
Try this (untested) command.

sed 's#/usr/local/mrtg-2/bin//mrtg#/usr/bin/mrtg#' infile > outfile

Add a g before the closing ' if the string can appear more then once on a line and you want to replace all occurrences. CaKiwi
 
Try using the following awk :
cat infile | awk '{while (sub("/usr/local/mrtg-2/bin//mrtg","/usr/bin/mrtg",$0)==1); print($0)}' >outfile
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top