Let's say I have two files like this:
1 a one ...
2 b two ...
3 c three ...
4 d four ...
5 e five ...
6 f six ...
and
a
c
f
Is there a way, not knowing the number of columns in file 1 (or not having to repeat each field), I can use join to get the matching lines
1 a one ...
3 c three ...
6 f six ...
I've tried
join -1 2 -o 1.0 file1 file2
like you'd write $0
to get all fields in awk
, but I obviously get invalid field number
.
join
for this case, but you can useawk 'NR==FNR{a[$1]; next} $2 in a' file2 file1