How does awk NF filename work?

I have the following file:

cat testing.txt
==============
line1 1
line2 2 2


line3 3 3

line4

I can understand how it works awk 'NF > 0' testing.txt. This command only processes the number of fields with more than 1 field from each record, and thus empty lines and tabs are deleted.

awk 'NF>0' testing.txt
line1 1
line2 2 2
line3 3 3
line4

However, I can’t understand how it works awk NF testing.txt. He does the same as above.

awk NF testing.txt
line1 1
line2 2 2
line3 3 3
line4

I do not indicate any conditions in this case. However, it works fine and removes blank lines and tab from each record.

I see a lot of links on the Internet saying that we can use this command to remove blank lines or tabs from a file. But I can not understand the syntax.

+4
source share
1 answer

NF N umber F ields. , NF 0, awk True. :

if NF>0  --> True
if NF==0 --> False

awk {print $0}, , :

if NF>0   --->  True   ---> {print $0}
if NF==0  --->  False  ---> nothing

, awk NF file : , . : .

+7

Source: https://habr.com/ru/post/1539779/


All Articles