Answer the question
In order to leave comments, you need to log in
Print in bash only duplicate lines from files?
Hello, I
need to output from two files only the lines that are in both files
. An example of the contents of the files:
cat 1.txt
11
22
33
33
cat 2.txt
33
11
44
Answer the question
In order to leave comments, you need to log in
tell me what i missed
$ cat *.txt | uniq -d
33
$ cat *.txt | sort | uniq -d
11
33
comm -12 <(sort 1.txt) <(sort 2.txt)
I would also suggest a solution like this:
But this is more of a python solution, and py is not shipped out of the box in the standard set.
Also, this solution is not efficient for large files.
py "set(open('1'))&set(open('2'))"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question