Page 1 of 1

findstr because of extra comma

Posted: 17 Jan 2018 10:01
by mungurk@gmail.com
Hello group,
We have a script that compares a file of email addresses (dump.txt) with a list of employees (pwd_raw.txt).
findstr /g:"dump.txt" "pwd_raw.txt" >output.txt

The file of email addresses has the email addresses, one per line, BUT it also includes a comma "," at the end of each line, immediately after the email address:
john.doe@company.com,
jenny.jones@company.com,

Because the list of employees in pwd_raw.txt does not include the comma "," the findstr is failing.

Our corporate IT policies are very strict and we cannot use apps that could easily remove the comma, such as FART or sfk.

Is there a way to:
1 - trim the comma from the email addresses
OR
2 - ignore the comma from the findstr

I have certainly been researching, including https://ss64.com/nt/findstr.html but have yet to find an answer I am able to use.

Any help would be appreciated.

Aisha

Re: findstr because of extra comma

Posted: 17 Jan 2018 12:33
by aGerman
I assume that would work for you:

Code: Select all

>"output.txt" (
  for /f "usebackq delims=," %%i in ("dump.txt") do findstr /c:"%%i" "pwd_raw.txt"
)
Of course it will take longer because findstr.exe has to be executed for each line in dump.txt.

Steffen

Re: findstr because of extra comma

Posted: 17 Jan 2018 12:38
by mungurk@gmail.com
many thanks - I have not seen code that starts with the intended filename at the beginning before - did not know that was possible.

so much still to learn

thanks

Re: findstr because of extra comma

Posted: 17 Jan 2018 12:53
by aGerman
viewtopic.php?f=3&t=8305
In your case it really doesn't matter if you write the redirection in front of the left parenthesis or after the right parenthesis. Meanwhile it's just one of my habits to always write redirections at the beginning of the line.

Steffen