nawk 'BEGIN{FS="|"} { if(NR==FNR) a[$3]=0 else { a[$3]++ if(a[$3]>=2) print "#"$0 else print $0 } }' 1.txt 2.txt