findstr because of extra comma

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mungurk@gmail.com
Posts: 6
Joined: 26 Sep 2016 15:02

findstr because of extra comma

#1 Post by mungurk@gmail.com » 17 Jan 2018 10:01

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

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

Re: findstr because of extra comma

#2 Post by aGerman » 17 Jan 2018 12:33

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

mungurk@gmail.com
Posts: 6
Joined: 26 Sep 2016 15:02

Re: findstr because of extra comma

#3 Post by mungurk@gmail.com » 17 Jan 2018 12:38

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

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

Re: findstr because of extra comma

#4 Post by aGerman » 17 Jan 2018 12:53

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

Post Reply