Search code examples
batch-filecmdfindstr

Using findstr to find non matching records in two text files


I am a librarian and have an issue.

I am often given lists of tapes to pull from the shelves and send out. I need to compare a list that I am given to a list of previously pulled tapes and populate a list of tapes on the first list that are not already out.

I know some basic command prompt and know that findstr is most likely the command which should be used however even upon very basic testing to try and debug what I have it comes up with no results even when I create scenarios in which the results should be there.

for example:

NEEDLE is a file containing the numbers {3,4,5,6} each on their own line

HAYSTACK is a file containing the numbers {1,2,3,4,5,6,7,8,9} also on their own lines

after I run findstr I expect to recieve a text file containing the numbers 1,2,7,8,9

I know that needle (the file containing the search strings) goes before the haystack (the file being looked through) but I am unsure the best way to do this.


Solution

  • findstr /v /x /g:NEEDLE HAYSTACK
    

    should return the result you want - but you've specified to return 3 which is in NEEDLE.

    The command means "find full lines (/x) that DO NOT match (/V) lines from needle (/g:NEEDLE)"