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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tr command - need to change string not characters 1

Status
Not open for further replies.

AlbertAguirre

Programmer
Nov 21, 2001
273
US
I need to duplilcate the last line in a file but change certain elements.

For instance:
tail -1 filename.txt

produces:
123 abc 456 def 123

I need to change all instances of "123" to "99".

I tried this:
tail -1 filename.txt | tr "123" "99"

But the result is:
993 abc 456 def 993

This is because "tr" does a character to character conversion. I need it to change the entire "123" string.

I cannot find the answer in man tr.

Help?
 
sed is the better tool for this.

Code:
tail -1 filename.txt | sed 's/123/99/g'


Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L
CompTIA Linux+
CompTIA Security+

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top