awk to replace a specific field in certain condition

Hi,

I have a file like below

PRUM,67016800          ,CC ,C1,67016800          ,  ,Y,Y,2 ,CK,BX,FOX                                     ,00000001,EA,00000001,20141120 00:00:00,               ,N,Y,Y,CK ABCDEF ,IN,000000047.0000,000000000.7500,000000005.7500,CI,000000202.6875,LB,000000000.6000,000000000.6000,20705032020722,                   ,A,                 ,20141120 00:00:00,   ,GS1 128   ,1.0000,                              ,09975284
PRUM,504608X           ,CC ,C1,504608X           , N ,Y,Y,2 ,CK,BX,FOX                                     ,00000005,EA,00000005,20141120 00:00:00,                 ,N,Y,Y,CK ABCDEF ,IN,000000010.2500,000000003.5000,000000004.2500,CI,000000152.4688,LB,000000000.5500,000000000.5500,20705032010150,                   ,A,                 ,20141120 00:00:00,   ,GS1 128   ,1.0000,                              ,09975172

Now, I would need to replace filed 6 value with "00" if it has null/blank value (like line 1) or leave it as is (like line 2)

Can anyone help me on this?

awk -F, '$6=="" {$6="00"} {print}'  infile >newfile
1 Like

If I read the requirements correctly I think the request was for something more like:

awk -F, '$6 ~ "^[[:blank:]]*$" {$6="00"} {print}' OFS=, infile >newfile
1 Like

Field 6 is not really null/blank. It is actually 2 spaces. Below regex should match null/blank field 6 as well as field 6 with one or more consecutive spaces.

awk 'BEGIN {FS=OFS=","} $6 ~ /^ *$/ { $6 = "00" }1' file

thanks a lot! Now, I need to filter out those lines that has field 17(which is a date field) either blank or less than equal to system date.

Appreciate your help.

So, with how we showed you to handle field #6, what have you tried to adapt what we showed you to work on your new problem?

Yes, I adopted the below one

awk 'BEGIN{FS=",";OFS=","} ($6=="  ") {$6="00"} {print $0}' filename

That is you old problem (and it doesn't do what you asked for).

I repeat, what have you tried to address your new problem?