To print common items in both files:
$ awk 'NR==FNR{a[$1];next}$1 in a{print $1}' file1 file2 "aba" "abc" "xxx"
Explanation:
NR and FNR are awk variables that store the total number of records and the number of records in the current files, respectively (by default, this is a string).
NR==FNR
If you want to combine whole lines, use $0 :
$ awk 'NR==FNR{a[$0];next}$0 in a{print $0}' file1 file2 "aba" 0 0 "xxx" 0 0
Or a specific set of columns:
$ awk 'NR==FNR{a[$1,$2,$3];next}($1,$2,$3) in a{print $1,$2,$3}' file1 file2 "aba" 0 0 "xxx" 0 0
Chris seymour
source share