Solved Omit quotation marks on certain rows based on search strings

June 4, 2012 at 01:08:11
Specs: Solaris
Hi Experts,

I would like to seek your assistance in getting the desired output of the following input:


INPUT FILE:

a_DATE : "Thu Apr 19 02:02:29 2012"
a_User-Name : "Rex_Smith"
a_Acct-Status-Type : "Alive"
a_Acct-Session-Id : "0800FFFF68024086-4F8E153C"
a_Service-Type : "Framed"
a_Framed-Protocol : "PPP"
a_RB-Acct-Update-Reason : "AAA-ACCT-PERIODIC"
a_Port : "2432718987"
a_RB-NAS: "2432696634"
a_NAS-Port-Type : "100"
a_NAS-Port-Id : "9/1 vlan-id 314 pppoe 22667"
a_RB-MAC : "00:0b:2b:43:93:f7"

DESIRED OUTPUT (omit quotation marks on some rows):

a_DATE : "Thu Apr 19 02:02:29 2012"
a_User-Name : Rex_Smith
a_Acct-Status-Type : "Alive"
a_Acct-Session-Id : "0800FFFF68024086-4F8E153C"
a_Service-Type : "Framed"
a_Framed-Protocol : "PPP"
a_RB-Acct-Update-Reason : AAA-ACCT-PERIODIC
a_Port : "2432718987"
a_RB-NAS: "2432696634"
a_NAS-Port-Type : 100
a_NAS-Port-Id : "9/1 vlan-id 314 pppoe 22667"
a_RB-MAC : 00:0b:2b:43:93:f7


MY OUTPUT (INCORRECT)
a_User-Name : Rex_Smith
a_RB-Acct-Update-Reason : AAA-ACCT-PERIODIC
a_NAS-Port-Type : 100
a_RB-MAC : 00:0b:2b:43:93:f7


My goal is to remove quotation marks (") on the lines that satisfy the search strings/list (a_User-Name, a_RB-Acct-Update-Reason, a_NAS-Port-Type, a_RB-MAC) by using awk and gsub but I am ecountering error. I decided not to use awk but row to be modified are just filtered aand updated without the other rows (not to be modified. Does anybody tried doing the same output? Can you please share how you achieve it?

Thanks and Regards,
Amiti


See More: Omit quotation marks on certain rows based on search strings

Report •

#1
June 4, 2012 at 09:54:00
✔ Best Answer
#!/bin/ksh

nawk ' BEGIN { FS=OFS=":";
refarr["a_User-Name"]=1
refarr["a_RB-Acct-Update-Reason"]=1
refarr["a_NAS-Port-Type"]=1
refarr["a_RB-MAC"]=1
}
{
gsub(" $", "", $1) # delete the space at the end of field 1
# print only those array elements defined - with no double quotes
if($1 in refarr)
   {
   gsub("\"","",$0)
   print $0
   }
} ' datafile.txt


Report •

#2
June 5, 2012 at 03:03:05
Hi Nail,

Really appreciate your prompt response. Can you please assist me in executing the script as when I tried running it, I am getting nothing. My system is Solaris10.

Thanks in advance Nail


Report •

#3
June 5, 2012 at 09:00:36
I am using Solaris 9, but the versions of nawk are probably the same.

So, let's start at the basics; any error messages??

Also, in my script, I called the input file - datafile.txt. Is that the issue?


Report •

Related Solutions

#4
June 5, 2012 at 21:55:07
Hi Nail,

There is no error message of any type and when I run the command line by line, there is no output. I just replace the datafile.txt with the appropriate input filename.

Thanks and Regards,
Amiti


Report •

Ask Question