Apr 7, 2004 #1 rk999 Technical User Joined Oct 21, 2002 Messages 8 Location 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 Joined Nov 8, 2002 Messages 53,708 Location 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 Joined Nov 8, 2002 Messages 53,708 Location 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 Joined Sep 20, 2001 Messages 464 Location 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 Joined Oct 21, 2002 Messages 8 Location US Thanks all. All three solutions works for my script !! Thanks again, RK Upvote 0 Downvote