Apr 7, 2004 #1 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
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
Apr 7, 2004 #2 PHV MIS Nov 8, 2002 53,708 FR 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 Upvote 0 Downvote
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
Apr 7, 2004 #3 PHV MIS Nov 8, 2002 53,708 FR 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 Upvote 0 Downvote
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
Apr 8, 2004 #4 aigles Technical User Sep 20, 2001 464 FR 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. Upvote 0 Downvote
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.
Apr 8, 2004 Thread starter #5 rk999 Technical User Oct 21, 2002 8 US Thanks all. All three solutions works for my script !! Thanks again, RK Upvote 0 Downvote