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

How to replace spaces with commas?

Status
Not open for further replies.

philthygeezer

Technical User
Jan 15, 2009
3
US
awk '{gsub(/,/," ");print}'

This will replace commas with spaces, but

awk '{gsub(/ /,",");print}'

Doesn't appear to do the reverse.

What do I do?
 
Perhaps this ?
awk '{gsub(/[ \t]/,",");print}'

or this ?
nawk '{gsub(/[ \t]/,",");print}'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Seems to work for me, what OS and version of awk?

Code:
$ echo "test is, allegedly, a test" | awk '{gsub(/,/," ");print}'
test is  allegedly  a test
$ echo "test is, allegedly, a test" | awk '{gsub(/ /,",");print}'
test,is,,allegedly,,a,test
$

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top