[Solved] Need to add Single quotes to particular lines

Hi Guys,

I have the following file.

DbName=DBNAME
DbUser=USERID
DbPass=PASSLL
SrcLocation=/appl/data/VSTAR
SrcFile1=gmb_dly_ind_sls_20120410133424.txt
SrcFile2=
IpLocation=/appl/data/VSTAR/global_daily/input/GMB
IpFile=gmb_dly_ind_sls_20120410133424.txt
OutLocation=/appl/data/VSTAR/global_daily/output
OutFile1=GMB_D_Stg_IndSls_Ld_040.txt
OutFile2=GMB_D_Stg_IndSls_Ld_040.txt
BatchTrkId=323
BusinessUnit=GMB
Country=BRAZIL
CurrSlsDate=
PriorSlsDate=

I like to search for Country and BusinessUnit keyword and I like to add Single quotes(') after + and at the end.
The Output should be as below.

DbName=GMNGSRDB
DbUser=NGSRALL
DbPass=NGSRALL
SrcLocation=/appl/data/VSTAR
SrcFile1=gmb_dly_ind_sls_20120410133424.txt
SrcFile2=
IpLocation=/appl/data/VSTAR/global_daily/input/GMB
IpFile=gmb_dly_ind_sls_20120410133424.txt
OutLocation=/appl/data/VSTAR/global_daily/output
OutFile1=GMB_D_Stg_IndSls_Ld_040.txt
OutFile2=GMB_D_Stg_IndSls_Ld_040.txt
BatchTrkId=323
BusinessUnit='GMB'
Country='BRAZIL'
CurrSlsDate=
PriorSlsDate=

Please somebody help me out here..

Cheers!!!!

Hi

awk -F"=" '/BusinessUnit|Country/{$2=q$2q}1' q="'" OFS="=" file

Guru.

1 Like

Thanks guruprasdpr,,, I came up with this command.

awk -F'=' '/Country|BusinessUnit/{print $1 "=\x27" $2 "\x27" }' 

But it was giving only those two records,, Can you tell me what i did wrong.

Cheers!!!!!

Hi

Its displaying only those two because your filter is set for only those 2. Try this:

awk -F'=' '/Country|BusinessUnit/{print $1 "=\x27" $2 "\x27";next}1' file

The '1' makes every line to get printed by default. The 'next' is to prevent those filtered lines from getting printed again by the '1'.

Guru.

Thanks for that explanation :slight_smile: