[PLUG] awk: is field blank?

Robert Citek robert.citek at gmail.com
Sat Oct 30 15:59:22 UTC 2021


A few pointers:
- {print $0} and {print} are the same
- {print} is the default action for any pattern match
- since you are printing the entire line, the OFS isn't used and,
therefore, doesn't need to be specified
- you don't need to specify an "if" as that is part of the structure of an
awk script: conditional {action}

Simplified version of your script:

BEGIN {FS="|"}
$8 != " "

... and an example:

$ echo -e "a|b|c|d\na|b||d" | awk -F'|' '$3 != ""'
a|b|c|d

Regards,
- Robert

On Sat, Oct 30, 2021 at 9:51 AM Rich Shepard <rshepard at appl-ecosys.com>
wrote:

> On Sat, 30 Oct 2021, Robert Citek wrote:
>
> > Here's a sample:
> > $ echo -e "a\tb\tc\td\na\tb\t\td" | awk -F'\t' '{print}'
> > a b c d
> > a b   d
>
> > $ echo -e "a\tb\tc\td\na\tb\t\td" | awk -F'\t' '$3=="" {print}'
> > a b   d
>
> My script uses if and awk doesn't like how I've used it:
> BEGIN {FS="|";OFS="|"}
> if {$8!=""} {
>        print $0
>     }
>
> gawk -f clean-broadway-file.awk mean-vel-broadway.dat > out.dat
> gawk: clean-broadway-file.awk:8: if {$8==""} {
> gawk: clean-broadway-file.awk:8: ^ syntax error
>
> I want to print the whole line only if $8 is not empty.
>
> Thanks,
>
> Rich
>



More information about the PLUG mailing list