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!

How to find/replace a character within a string?

Status
Not open for further replies.

goyalpdm

Programmer
Jan 11, 2003
42
0
0
US
Hi,

Am using Ksh and have the string in a variable. The string contains ' and would like to append / before same. So ' should be replaced as /'. Please advise.

Thanks,
Sachin
 
Hi

As far as I know,this should work in [tt]ksh[/tt] too :
Code:
your_string=${your_string//\'//\'}

Ps : I think this question belongs to forum822 ( UNIX Scripting ).

Feherke.
 
The code returns bad substitution.

PS: Not too sure on how to change the forum. If you can, please do it for me.
 
Try:

Code:
str=$(echo ${str}|sed "s:':/':g")


HTH,

p5wizard
 
Can please suggest the command if ' should be modified to \' (instead of /' as mentioned earlier)?

I tried str=$(echo ${str}|sed "s:':\':g"): but it is of no help.
 
You need to quadruple the '\' character:

str=$(echo ${str}|sed "s:':\\\\':g"

Double, because between double quotes you need to quote the special char '\' ...
Double again, because sed needs you to quote the special char '\' in order to get a '\' without special meaning ...


HTH,

p5wizard
 
Perfect again! Good learning. Thanks a ton.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top