Page 1 of 1

findstr with hyphens

Posted: 08 Jun 2010 08:07
by b4bblefish
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.

Re: findstr with hyphens

Posted: 08 Jun 2010 10:21
by aGerman
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

Re: findstr with hyphens

Posted: 08 Jun 2010 12:46
by b4bblefish
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.