Обсуждение: Help with awk script
Can anyone help with the following:
Using awk I need to replace every occurance of single quote with a double quote in the string IN ('x','y','z',......). There can be any number of elements in single quotes in between the brackets.
IN ('x','y','z'',...) -> IN ("x","y","z",....)
Thanks
Atif
---------- Forwarded message ----------
From: Atif Jung <atifjung@gmail.com>
Date: 20 April 2010 16:47
Subject: Re: [NOVICE] Help with awk script
To: steve@retsol.co.uk
Atif
From: Atif Jung <atifjung@gmail.com>
Date: 20 April 2010 16:47
Subject: Re: [NOVICE] Help with awk script
To: steve@retsol.co.uk
I found another way, using the octal values for ' and ".
awk 'gsub("\047","\042") {print}'
Rgds
Atif
On 20 April 2010 16:41, Steve T <steve@retsol.co.uk> wrote:
Try:
a="'N','Y','B'"
echo $a|awk '{gsub("'"'"'","\"",$0);print $0}'
NB the differences between ' and " in the the gsub command - it effectively starts a quoted sting (with a double quote) then ends the awk script with a single quote then quotes a single quote (ie single quote in double quotes), restarts the script with a single quote and then closes that with a double quote!
There's probably a far easier way using [quote] or escaping the quotes - but the above appears to work.On Tue, 2010-04-20 at 11:44 +0100, Atif Jung wrote:Can anyone help with the following:Using awk I need to replace every occurance of single quote with a double quote in the string IN ('x','y','z',......). There can be any number of elements in single quotes in between the brackets.IN ('x','y','z'',...) -> IN ("x","y","z",....)Thanks
Atif
Steve Tucknott
ReTSol Ltd
DDI: 01323 488548