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

Replace Character Occurences 1

Status
Not open for further replies.

Michael42

Programmer
Joined
Oct 8, 2001
Messages
1,454
Location
US
Hello,

In a Bourne shell script I have a list of items delimited by a comma and I would like to change this, setting it to a variable, to be delimited by spaces.

In other words, I want to convert all the commas to spaces in the list and set this to a variable.

Code:
TABLES1="a,b,c,d"
TABLES2="[b]<same list a TABLES1 but delimited by spaces>[/b]"

What can you advise?

Thanks,

Michael42
 
Hi

Code:
[gray]# bash & ksh, not sure about sh[/gray]
TABLES2="${TABLES1//,/ }"

[gray]# any shell[/gray]
TABLES2=`echo "$TABLES1" | tr ',' ' '`

Feherke.
 
feherke,

P-E-R-F-E-C-T! :-)

Thanks for posting,

Michael42
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top