Using awk to determine if field value is valid

Hi Forum.

I tried to search the forum posts for an answer but I haven't been able to do so for what I'm trying to accomplish.

I have the following source file:

11936385~TFSA|11936385|4431|3401458067|10/09/1982|25.00|IBSBONUS|3200|||||CASH|
3401458067|1005|
21936385~TFSA|11936385|4431|3401458067|10/09/1982|0|IBSBONUS|3200|||||CASH|3401
458067|1005|
31936385~TFSA|11936385|4431|3401458067|10/09/1982|A|IBSBONUS|3200|||||CASH|3401
458067|1005|
41936385~TFSA|11936385|4431|3401458067|10/09/1982||IBSBONUS|3200|||||CASH|34014
58067|1005|

Field#6 has to be a dollar amount or count value greater than zero. So for this example, first record is valid while the last 3 records are not valid.

This is the code that I have so far but it's not returning the correct expected results:

awk -F"|" '$6=="" || $6=="0" || $6 !~ /^[0-9]*.[0-9]*$/ {print $0}' filename

Thanks for your help.

Try:

awk -F\| '$6+0>0' file
1 Like

Gee - that was just a simple but elegant solution. :stuck_out_tongue:

It could be shortened still: :slight_smile:

awk -F\| '$6+0' file