Computing.Net > Forums > Unix > replace characters in string

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

replace characters in string

Reply to Message Icon

Name: frankliu9 (by hlliu98)
Date: March 27, 2006 at 22:11:36 Pacific
OS: unix
CPU/Ram: Intel
Product: PC
Comment:

I have a string variable x=A_B_C_D in the script, what I want to do is to replace all the “_” with the space, after that,
x=A B C D. My system only supports Bourne shell /bin/sh and Korn shell /bin/ksh (no bash).

Can anyone help me?

Thanks in advance.



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: March 28, 2006 at 06:54:43 Pacific
Reply:

#!/bin/ksh

x=A_B_C_D
# replace _ with a space
x=$(echo $x|sed 's/_/ /g')

echo $x


0

Response Number 2
Name: frankliu9 (by hlliu98)
Date: March 28, 2006 at 09:33:15 Pacific
Reply:

It works. Thank you very much.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: replace characters in string

Replace characters in file names www.computing.net/answers/unix/replace-characters-in-file-names/6079.html

replace data in a file www.computing.net/answers/unix/replace-data-in-a-file/6189.html

find unwanted characters in file www.computing.net/answers/unix/find-unwanted-characters-in-file/7046.html