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

String Match and Replace

Status
Not open for further replies.

oldtimer47

Programmer
Apr 18, 2003
2
US
ksh:
I need to match and replace a string. The string is set in a variable. Is there a simple command or way to do it? (ex. in ksh93 there's ${var/pattern/replace})

I've been away from unix scripting for a while, I'm rusty ...
 
use the sed editor...
sed /s/pattern/replcement/[flag]

example
>echo "abc xyz" | sed s/xyz/123/g
returns "abc 123"

Note: the g is optional - used to to replace all instances of pattern on line (not just first)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top