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!

Replace a character in a variable

Status
Not open for further replies.

cbsm

Programmer
Oct 3, 2002
229
0
0
FR
I know how to replace a character in a file (using grep for example).
What I need to do is to replace a character in a variable :
MyVar="abcd/ter/123"
and I need to replace "/" with "_"
(in the end I want MyVar="abcd_ter_123"

It's probably soooooo easy ... but I'm stuck ...

Thank you !!!
 
In less modern shells...

Code:
# Ksh
MyVar=$(echo ${MyVar} | sed 's|/|_|g')

# bourne
MyVar=`echo ${MyVar} | sed 's|/|_|g'`



 
Thanks - that was easy ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top