New answers tagged

2

Use comm first sort the files: sort file1 -o file1_sorted sort file2 -o file2_sorted Of course you can use sort file1 -o file1 To sort in-place then use comm as following: comm -2 3 file2_sorted file1_sorted > newfile comm compares sorted files Or if your shell supports process substitution (bash, zsh and some kshs): comm -23 <(sort file2) ...


1

one way using awk -- echo -e "a\t1\na\t2\nb\t1\nc\t1\nc\t2\nd\t1\ne\t1\ne\t2\ne\t3\nf\t1" | awk '{a[$1] = $0; count[$1]++} END{for (i in a) {if (count[i]== 1) print a[i]} }' b 1 d 1 f 1 For the 2nd col, the unique value is 3 - you've shown f 3 as the desired output - shouldn' it be "e 3" ? echo -e ...


1

awk 'NR==1 { lastcol1=$1; lastline=$0; next; } { if ($1==lastcol1) { repeated=1; next; } if (repeated==0) print lastline; lastcol1=$1; lastline=$0; repeated=0; } END { if (repeated==0) print lastline; }' input b 1 d 1 f 1



Top 50 recent answers are included