findstr with hyphens

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
b4bblefish
Posts: 2
Joined: 08 Jun 2010 07:53

findstr with hyphens

#1 Post by b4bblefish » 08 Jun 2010 08:07

Hi all,

I am trying to use the findstr command to search for matches for any of the many vendors I have in another text file in a large CSV file. The command right now is:

findstr /g:Vendors.txt "ServiceRpt.csv" > out.csv

where vendors.txt contains the list of vendor names and servicerpt.csv is the large csv file.

However, some of the vendor names have hyphens and spaces in them, and the service report contains basically every ascii character possible (/\!@#$%^&*()? etc...). As a result findstr does not properly find all the entries, it finds most of them, but entries that are near or contain lines that have hyphens in them start getting ignored or other strange things start happening. Could anybody tell me what I'm missing?

ex: one of my vendor names is MTI - i, if i do findstr "MTI - i" "ServiceRpt.csv" > out.csv
it just returns ALL the lines instead of just the ones that contain MTI - i, I've also tried using the /l flag with no luck, it returns the same thing. I would like to just literally take the strings from the vendor list and match them literally to the csv file.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: findstr with hyphens

#2 Post by aGerman » 08 Jun 2010 10:21

If you use
findstr "MTI - i" "ServiceRpt.csv" > out.csv
then you are looking for lines which contain "MTI" or "-" or "i".

Try:-
findstr /c:"MTI - i" "ServiceRpt.csv" > out.csv
and
findstr /x /g:Vendors.txt "ServiceRpt.csv" > out.csv

Regards
aGerman

b4bblefish
Posts: 2
Joined: 08 Jun 2010 07:53

Re: findstr with hyphens

#3 Post by b4bblefish » 08 Jun 2010 12:46

The /x just gives me back nothing, the lines aren't exact matches, but lines from a SQL database and i'm just matching the vendor name in each line. Thanks for your help though, helped me understand why "MTI - x" kept messing up.

Post Reply