Set difference from two files in unix
That's typically what join
is for:
join -v2 setA setB
That's joining the files on the first column (which is assumed to be sorted lexically), and print the rows of the second file which are not paired.
awk 'NR==FNR {key[$1]; next} !($1 in key)' setA setB
1 123
3 def
That reads the first file and stores the "ids" in the array "key", then it only prints from the 2nd file if the id is not in the key array.