Awk to skip the blank lines

There are two approaches you can try to filter out lines:

awk 'NF' data.txt

and

awk 'length' data.txt

Just put these at the start of your command, i.e.,

awk -v variable=$bashvariable 'NF { print variable ... }' myinfile

or

awk -v variable=$bashvariable 'length { print variable  ... }' myinfile

Both of these act as gatekeepers/if-statements.

The first approach works by only printining out lines where the number of fields (NF) is not zero (i.e., greater than zero).

The second method looks at the line length and acts if the length is not zero (i.e., greater than zero)

You can pick the approach that is most suitable for your data/needs.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)