Operating System - Linux
1827808 Members
13083 Online
109969 Solutions
New Discussion

Re: awk? script wanted to strip data from record

 
SOLVED
Go to solution
James A. Donovan
Honored Contributor

awk? script wanted to strip data from record

I have a comma-delimited file with multiple record types. I need to null-out the 12th field of any records whose first field has the value "RACT0010". The output should be written to a new file.


I'm thinking this is something awk could handle in a couple of lines, but I don't have time to mess with it.
Any help would be appreciated...

RFIN0011,PFEE,DEP,TD,145376,282410,30774698,USD,22792601,AX,,"Conveyed Dep. Fee",S,2,0.0200,35.00,0,-0.04
HACT0010,144509,10/25/2006,10/25/2006,10/26/2006,04:43:57
RACT0010,10/25/2006,184218,"sonyon","61025.0006b",2,TD,145376,USD,"147dad12c",,4444444444444444,08/07,5.00,MC,D,10/23/2006,681559,100,,,,5945
RACT0010,10/25/2006,184218,"sonyon","61025.0006b",3,TD,145376,USD,"147dad132",,4444444444444444,09/10,25.00,AX,D,10/23/2006,180392,100,,,,5945
RACT0010,10/25/2006,184218,"sonyon","61025.0006b",4,TD,145376,USD,"12a0e5698",,4444444444444444,08/07,-10.00,MC,R,,,,,,,5945
RACT0010,10/25/2006,184218,"sonyon","61025.097Eb",2,TD,145376,USD,"165a8362c",,4444444444444444,09/10,10.00,AX,D,10/24/2006,164110,100,,,,5945
RACT0010,10/25/2006,184218,"sonyon","61025.097Eb",3,TD,145376,USD,"165a83624",,4444444444444444,08/08,25.00,VI,D,10/24/2006,03693A,100,,,,5945
*DFREND,PID=945479,FREQ=DAILY,CO=144509
Remember, wherever you go, there you are...
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: awk? script wanted to strip data from record

Hi James:

# awk -F"," '{if ($1~/^RACT0010/) {$12=""};print}' file > file.out

Regards!

...JRF...
James A. Donovan
Honored Contributor

Re: awk? script wanted to strip data from record

James,

Thanks for the quick response. Your solution is close, but it stripped out the commas from the record, which I need for the final output.

Result:

RFIN0011,PFEE,DEP,TD,145376,282410,30774698,USD,22792601,AX,,"Conveyed Dep. Fee",S,2,0.0200,35.00,0,-0.04
HACT0010,144509,10/25/2006,10/25/2006,10/26/2006,04:43:57
RACT0010 10/25/2006 184218 "sonyon" "61025.0006b" 2 TD 145376 USD "147dad12c" 08/07 5.00 MC D 10/23/2006 681559 100 5945
RACT0010 10/25/2006 184218 "sonyon" "61025.0006b" 3 TD 145376 USD "147dad132" 09/10 25.00 AX D 10/23/2006 180392 100 5945
RACT0010 10/25/2006 184218 "sonyon" "61025.0006b" 4 TD 145376 USD "12a0e5698" 08/07 -10.00 MC R 5945
RACT0010 10/25/2006 184218 "sonyon" "61025.097Eb" 2 TD 145376 USD "165a8362c" 09/10 10.00 AX D 10/24/2006 164110 100 5945
RACT0010 10/25/2006 184218 "sonyon" "61025.097Eb" 3 TD 145376 USD "165a83624" 08/08 25.00 VI D 10/24/2006 03693A 100 5945
Remember, wherever you go, there you are...
spex
Honored Contributor

Re: awk? script wanted to strip data from record

Hi,

awk -F"," '{if ($1~/^RACT0010/) $12=""; print $1","$2","$3","$4","$5","$6","$7","$8","$9","$10","$11","$12","$13","$14","$15","$16","$17","$18","$19","$20","$21","$22","$23}' < file_in > file_out

PCS
James R. Ferguson
Acclaimed Contributor
Solution

Re: awk? script wanted to strip data from record

Hi (again) James:

How about(?):

# awk -F"," 'BEGIN{OFS=","};{if ($1~/^RACT0010/) {$2=""};print}' file > file.new

Regards!

...JRF...
James A. Donovan
Honored Contributor

Re: awk? script wanted to strip data from record

Works! thanks...
Remember, wherever you go, there you are...