Each line of column in file as key in awk

You may try this awk:

awk 'FNR==NR{seen[$2]; next} ($1 FS $2) in seen' file1 FS=_ file2
19-0000_Lname-yy-zzz_000-111
19-0001_Lname-yyyy-zzzzz_000-111

Alternatively this should also work:

awk 'FNR==NR{seen[$2]; next} {s=$0; sub(/_[^_]+$/, "", s)} s in seen' file1 FS=_ file2

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top