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

modify string

Status
Not open for further replies.

rk999

Technical User
Oct 21, 2002
8
US
Hi all script experts,
I have one string like below

SOLARIS UNIX SHELL

I want to convert this string like below ( add single quotes marks for each word and separate two words with comma )

'SOLARIS','UNIX','SHELL'

Thanks for your help
RJK


 
Try something like this:
echo "SOLARIS UNIX SHELL" | awk "{
for(i=1;i<NF;++i)printf \"'%s',\",\$i
printf \"'%s'\\n\",\$NF
}"

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
And the sed way:
echo "SOLARIS UNIX SHELL" | sed "s!^!'!;s! *!','!g;s!\$!'!"

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Another Awk script
[tt]
echo "SOLARIS UNIX SHELL" | awk -v OFS=',' '{
for (i=1;i<=NF;i++) $i="\047" $i "\047";
print
}'[/tt]

Jean Pierre.
 
Thanks all.
All three solutions works for my script !!

Thanks again,
RK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top