How to print line if field matches?

Hi all,

I got several lines line this
a b c d e 1 e
a 1 c d e 3 f
a b c 1 e 8 h
a b c d e 1 w
a 1 c d e 2 w
a b c d e 1 t
a b c d e 7 4

How can I print the line if 1 is the field one before the last field?
Basicly this 2 field ?
a b c d e 1 e
a b c d e 1 t

The file I got is huges.

Thanks

Try this

awk '$(NF-1)=="1"' file

Regards,
Gaurav.

awk '!($(NF-1)-1)' file

:wink:

Only for this special sample input.

grep "1..$" infile

Can we remove the quotes ? will be shorter :wink:

# sed -e 'N;h' -e 's/. . . . . \(.\) .\n. . . . . \(.\) .*$/\1\2/' -e '/1$/x;s/.*\n\(.*\)/\1/' -e '/^1/x;s/\(.*\)\n.*/\1/' infile \
> |sed -e '$h' -e '/. . . . . \(.\) .\1/x;!s/11.*//' -e '/^$/d' -e '/^[^1]*$/d'
a b c d e 1 e
a b c d e 1 w
a b c d e 1 t
# cat infile
a b c d e 1 e
a 1 c d e 3 f
a b c 1 e 8 h
a b c d e 1 w
a 1 c d e 2 w
a b c d e 1 t
a b c d e 7 4

Read this 8 Powerful Awk Built-in Variables � FS, OFS, RS, ORS, NR, NF, FILENAME, FNR (link removed) for NF,NR etc.

Thanks for the replies
Got it working :wink: