[PLUG] Gawk script not working as intended
Reid
nrwahl at protonmail.com
Mon May 20 21:06:33 UTC 2019
Works on my machine. Maybe you've got a Unicode single-quote?
[reid at laptop ~]$ cat test
#!/usr/bin/gawk
BEGIN { FS=OFS="," }
{
if ($5 ~/'Legal Contact'/) # double quotes also fail
next
else
print $0
}
[reid at laptop ~]$ gawk -f test input.txt
'fld1','fld2','fld3','fld4','fld5'
'fee','fie','foh','fum','Keep Me'
Sent with ProtonMail Secure Email.
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Monday, May 20, 2019 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