Extract lines from a file using a strings list [resolved]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
zimxavier
Posts: 53
Joined: 17 Jan 2016 10:09
Location: France

Extract lines from a file using a strings list [resolved]

#1 Post by zimxavier » 01 Feb 2016 08:42

After several hours to try to do it myself, i give up... again. :oops:

I have a list of strings in a file.

STRINGS.txt
string1
string2
string3
string4

I need to extract to output.txt all lines from input.txt which contain at least one of the strings from STRINGS.txt (a string = an entire line). I also need to extract all lines from input.txt that does not contain any strings, but i guess i will simply add a /v to findstr.

I could use a single line but in this case i think i can't use a space as part of the string (if i put a space at the beginning of a line in my STRINGS.txt, i.e before string in the strict sense, it finds no fake lines like "fakestring1"). Moreover, sometimes i have up to 200 strings...

Thanks in advance.


-----------------------------
EDIT:

Solution :mrgreen: :
First case :
findstr /g:STRINGS.txt input.txt > output.txt
Second case :
findstr /v /g:STRINGS.txt input.txt > output.txt

Post Reply