In Print lines in file from the match line until end of file I learnt that you can use 0
in range expressions in awk
to match until the end of the file:
awk '/matched/,0' file
However, today I started playing around this 0
and I found that this also works:
awk '/matched/,/!./' file
I guess 0
is working because in the range expression /regex1/,/regex2/
the lines are printed until the regex2
evaluates as True. And since 0
evaluates as False, this never happens and it ends up printing all the lines. Is this right?
However, with /!./
I would imagine this to work until a line without any character is found, like if we said awk '/matched/,!NF'
. But it does not: instead, it always evaluates to False. What is the reasons for this?
Examples
$ cat a
1
matched
2
3
4
end
Both awk '/matched/,/!./' a
and awk '/matched/,0' a
return:
matched
2
3
4
end
Whereas awk '/matched/,!NF' a
returns:
matched 2