3

Using awk, I would like to print the first column of every line after and including the 5th line, ignoring lines containing only whitespace characters.

I have tried

awk '!/^\s*$/ NR>4 {print $1}'

but it doesn't seem to work as expected.

Example input:

do not take this line
do not take this line
do not take this line
do not take this line
 take no    no      no
             
take  no      no      no
            
   take      no     no      no

Should result in:

take
take
take
0

1 Answer 1

4

You can check that the number of fields is non-zero:

$ awk 'NR>4 && NF>0 {print $1}' file
take
take
take

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .