Concatenating strings to "tr" command output

Hi All,

Please help me in forming command for the following scenario.

My input string (msg)is \'01\',\'02\',\'03\',\'04\',\'05\',\'06\' , i have removed \ and ' using

echo $msg|tr -d '\\'|tr -d "'"

which gave me output as
01,02,03,04,05,06.

I am half done here. Now i want to append single quotes at the beginning and ending of this out , with in the same command. I tried below command

echo $msg|tr -d '\\'|tr -d "'"|print "'"$msg"'"

.

But i am getting output as ''01','02','03','04','05','06''.

Please help me to get the output in below format
'01,02,03,04,05,06'.

Thanks in advance

This works for me in bash:

echo "'"${msg//\'/}"'"
1 Like
echo $msg|sed "s/'//g"
msg="\'01\',\'02\',\'03\',\'04\',\'05\',\'06\'"
echo "$msg"|sed "s:\\\'::g;s/^/'/;s/$/'/"

producing

'01,02,03,04,05,06'
1 Like
echo "01,02,03,04,05,06"|sed -e "s/^/'/g" -e "s/$/'/g"

Thanks all for the replies. You solved my problem :slight_smile:

Just wanted to check if i can achieve it without using sed or awk ?

See my earlier reply.

chpsam, to your output you can append ' at the beginning by piping to sed "s/^/'/" and to append at the end by piping the previous output to sed "s/$/'/".
please check if it works.

1 Like

This is in reply to User8. Thanks for your inputs, tried it, but getting error as below. I am running on AIX 6

$ msg="\'01\',\'02\',\'03\',\'04\',\'05\',\'06\'"
$ echo "'"${msg//\'/}"'"
ksh: "'"${msg//\'/}"'": 0403-011 The specified substitution is not valid for this command.