The following awk
command will display all lines from file
that has a -
in its penultimate whitespace-delimited column, and a positive integer in its last whitespace-delimited column:
awk '$(NF-1) == "-" && $NF ~ /^[0-9]+$/' file
The following grep
command would do the same thing:
grep -E -e '-[[:space:]]+[0-9]+$' file
The -E
is needed to understand the +
modifier in the pattern, and -e
is needed to stop grep
from interpreting the -
in the pattern as a command line option (-e
could also be changed replaced by --
, which signals the end of any command line options).