user3459079
user3459079

Reputation: 11

Eliminate single quoted strings using SED in UNIX

In my file I have the contents like below.

<sql type="cognos">SELECT * FROM  [PG WIND JAROS - JAROSODS].AGREMENT_MAS WHERE FILTER = 'Saravana' and ADDress = '32/36 Abc Nagar CH' </sql>
<sql type="cognos">select OBJECT_TYPE           'Object Type',
 OBJECT_NAME            "Object Name",
from [PG WIND Jaros - JAROSDM].CX_WIND_LOOKUP_REF WHERE Filter = 'Kumaar' and STATUS = 'RICH' </sql>

Here I have to convert everything to lower case except strings in single quotes. i.e.,

output:

<sql type="cognos">select * from  [pg wind jaros - jarosods].agrement_mas where filter = 'Saravana' and address = '32/36 Abc Nagar CH' </sql>
<sql type="cognos">select object_type           'Object Type',
 object_name            "object name",
from [pg wind jaros - jarosdm].cx_wind_lookup_ref where filter = 'Kumaar' and status = 'RICH' </sql>

How can I acheive this in SED ? Please help me .....

Upvotes: 0

Views: 60

Answers (2)

Gerrit Brouwer
Gerrit Brouwer

Reputation: 750

Here is a sed solution:

sed -e "s/^\([^']*\)$/\L\1/" -e "s/\([^']*\)\('[^']*'\)/\L\1\E\2/g" -e "s/\('[^']*\)$/\L\1/" file

\L turns the replacement to lower case (until \E is found).

http://www.gnu.org/software/sed/manual/sed.html

Upvotes: 0

Jotne
Jotne

Reputation: 41460

Here is one awk solution:

awk -F\' '{for (i=1;i<=NF;i++) printf "%s"(NF==i?RS:FS),(i%2?tolower($i):$i)}' file
<sql type="cognos">select * from  [pg wind jaros - jarosods].agrement_mas where filter = 'Saravana' and address = '32/36 Abc Nagar CH' </sql>
<sql type="cognos">select object_type           'Object Type',
 object_name            "object name",
from [pg wind jaros - jarosdm].cx_wind_lookup_ref where filter = 'Kumaar' and status = 'RICH' </sql>

Upvotes: 1

Related Questions