Solution 1:

I want to extract the duplicates

Use the following command line:

Findstr /i /x /g:text.txt text1.txt

Where:

  • /I Case-insensitive search
  • /X Prints lines that match exactly.
  • /G:StringsFile Get 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.


Further Reading

  • An A-Z Index of the Windows CMD command line | SS64.com
  • Windows CMD Commands (categorized) - Windows CMD - SS64.com
  • Findstr - Search for strings - Windows CMD - SS64.com