Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Concatenating strings to "tr" command output

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-12-2013
chpsam chpsam is offline
Registered User
 
Join Date: Jun 2012
Last Activity: 27 August 2013, 6:10 AM EDT
Posts: 19
Thanks: 8
Thanked 2 Times in 1 Post
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
Code:
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

Code:
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
Sponsored Links
    #2  
Old Unix and Linux 02-12-2013
user8 user8 is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 24 April 2013, 10:34 AM EDT
Posts: 36
Thanks: 0
Thanked 19 Times in 14 Posts
This works for me in bash:
Code:
echo "'"${msg//\'/}"'"

The Following User Says Thank You to user8 For This Useful Post:
chpsam (02-12-2013)
Sponsored Links
    #3  
Old Unix and Linux 02-12-2013
srinivas matta srinivas matta is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 21 February 2013, 2:05 AM EST
Location: Hyderabad
Posts: 30
Thanks: 0
Thanked 8 Times in 8 Posts

Code:
echo $msg|sed "s/'//g"

    #4  
Old Unix and Linux 02-12-2013
elixir_sinari's Unix or Linux Image
elixir_sinari elixir_sinari is offline Forum Advisor  
Registered User
 
Join Date: Mar 2012
Last Activity: 16 September 2016, 7:22 AM EDT
Location: India
Posts: 1,413
Thanks: 101
Thanked 497 Times in 474 Posts

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

producing

Code:
'01,02,03,04,05,06'

The Following User Says Thank You to elixir_sinari For This Useful Post:
chpsam (02-12-2013)
Sponsored Links
    #5  
Old Unix and Linux 02-12-2013
busyboy busyboy is offline
Registered User
 
Join Date: Jan 2010
Last Activity: 6 September 2016, 7:36 AM EDT
Posts: 195
Thanks: 2
Thanked 9 Times in 9 Posts

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


Last edited by Franklin52; 02-12-2013 at 08:48 AM.. Reason: Please use code tags for data and code samples
Sponsored Links
    #6  
Old Unix and Linux 02-12-2013
chpsam chpsam is offline
Registered User
 
Join Date: Jun 2012
Last Activity: 27 August 2013, 6:10 AM EDT
Posts: 19
Thanks: 8
Thanked 2 Times in 1 Post
Thanks all for the replies. You solved my problem Linux

Just wanted to check if i can achieve it without using sed or awk ?
Sponsored Links
    #7  
Old Unix and Linux 02-12-2013
user8 user8 is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 24 April 2013, 10:34 AM EDT
Posts: 36
Thanks: 0
Thanked 19 Times in 14 Posts
Quote:
Originally Posted by chpsam View Post
Just wanted to check if i can achieve it without using sed or awk ?
See my earlier reply.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
finding the strings beween 2 characters "/" & "/" in .txt file Behrouzx77 Shell Programming and Scripting 10 10-25-2012 09:48 AM
awk command to replace ";" with "|" and ""|" at diferent places in line of file shis100 Shell Programming and Scripting 7 03-16-2011 08:59 AM
"Join" or "Merge" more than 2 files into single output based on common key (column) Katabatic Shell Programming and Scripting 1 05-20-2010 11:41 AM
Explanation of "total" field in "ls -l" command output proactiveaditya UNIX for Dummies Questions & Answers 1 04-18-2010 01:40 AM
Debian: doubt in "top" %CPU and "sar" output jaduks Debian 0 09-12-2007 08:05 AM



All times are GMT -4. The time now is 04:20 AM.