Let's say I have:
text.txt with
1
2
3
4
5
and another text2.txt with
9
4
2
1
7
And I want to extract the duplicates:
2
1
4
Note: I'm using windows, I want it to be as easy as possible
Let's say I have:
text.txt with
1
2
3
4
5
and another text2.txt with
9
4
2
1
7
And I want to extract the duplicates:
2
1
4
Note: I'm using windows, I want it to be as easy as possible
Use the following command line:
Findstr /i /x /g:text.txt text1.txt
Where:
/ICase-insensitive search/XPrints lines that match exactly./G:StringsFileGet search string from a file
Source: Findstr - Search for strings - Windows CMD - SS64.com
Example:
F:\test>type text.txt
1
2
3
4
5
F:\test>type text1.txt
9
4
2
1
7
F:\test>Findstr /ixg:text.txt text1.txt
4
2
1
F:\test>Findstr /ixg:text1.txt text.txt
1
2
4
Note that there is no easy way to get the output in the order specified in the question:
2
1
4
as neither of the files contain the lines in that order.
With a Unix environment (cygwin on Windows), I would first sort both files (sort text.txt > text.txt.sorted, idem for the second file), then use comm -12 text.txt.sorted text2.txt.sorted