[PLUG] Gawk script not working as intended

Robert Citek robert.citek at gmail.com
Mon May 20 21:05:10 UTC 2019


This is what I am getting:

$ cat plug.awk
#!/usr/bin/awk

BEGIN { FS=OFS="," }
{ if ( $5 ~ /'Legal Contact'/ ) # double quotes also fail
         next
   else
         print $0
}

$ cat plug.txt
'fld1','fld2','fld3','fld4','fld5'
'fee','fie','foh','fum','Keep Me'
'fee','fie','foh','fum','Legal Contact'

$ awk -f ./plug.awk plug.txt
'fld1','fld2','fld3','fld4','fld5'
'fee','fie','foh','fum','Keep Me'

Is that what you are looking for?

Regards,
- Robert

On Mon, May 20, 2019 at 1:53 PM Rich Shepard <rshepard at appl-ecosys.com>
wrote:

> I have a long CSV file with two rows for each entity and I want to print
> only the first row to the output file. It's so simple that despite my
> research in using awk I'm not seeing my error.
>
> Gawk script:
>
> #!/usr/bin/gawk
>
> BEGIN { FS=OFS="," }
> { if ($5 ~/'Legal Contact'/) # double quotes also fail
>          next
>    else
>          print $0
> }
>
> The script also fails my expectation if the if statement is
>         if ( $5 == "Legal Contact" )
>
> Sample input file:
>
> 'fld1','fld2','fld3','fld4','fld5'
> 'fee','fie','foh','fum','Keep Me'
> 'fee','fie','foh','fum','Legal Contact'
>
> The output I want is only the first line, but both lines are printed to the
> output file. What simple thing am I missing?
>
> TIA,
>
> Rich
> _______________________________________________
> PLUG mailing list
> PLUG at pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug
>



More information about the PLUG mailing list