20

i have 4 files which are like

       file A
       >TCONS_00000867
       >TCONS_00001442
       >TCONS_00001447
       >TCONS_00001528
       >TCONS_00001529
       >TCONS_00001668
       >TCONS_00001921

       file b
       >TCONS_00001528
       >TCONS_00001529
       >TCONS_00001668
       >TCONS_00001921
       >TCONS_00001922
       >TCONS_00001924

       file c
       >TCONS_00001529
       >TCONS_00001668
       >TCONS_00001921
       >TCONS_00001922
       >TCONS_00001924
       >TCONS_00001956
       >TCONS_00002048

       file d
       >TCONS_00001922
       >TCONS_00001924
       >TCONS_00001956
       >TCONS_00002048

all files contain more than 2000 lines and sorted for first column.

i want to find common lines in all files. i tried awk and grep and comm but not working

25

Since the files are already sorted:

comm -12 a b |
  comm -12 - c |
  comm -12 - d
|improve this answer|||||
5
cat a b c d |sort |uniq -c |sed -n -e 's/^ *4 \(.*\)/\1/p'
|improve this answer|||||
  • Actually, save the sed, this is quite good for finding duplicate lines across many files: cat to sort to uniq -c. Somehow I didn't quite think of this, good answer! – smaslennikov May 21 '19 at 21:35
  • You can also use uniq command to only print duplicated lines: uniq -cd – mems Sep 30 '19 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.