MivaScott
MivaScott

Reputation: 1806

Filter text read from a file in Windows DOS batch

I'm trying to read in the contents of multiple .txt files and output the contents of each to a single file. The hitch is that the .txt files I'm reading are the email address I want, and then a tab. The single output file I'd like a just have the email address enclosed in quotes.

So the input file will be

[email protected]{tab}  
[email protected]{tab}  

and the output should be

'[email protected]',  
'[email protected]',  
'[email protected]',  
'[email protected]',  

Note that the output file will be a concatenation of all input files read.

Here is what I have so far to read all the input files. How do I craft the DO so that at the very least it will remove the tab, and for bonus points add in the quotes and commas.

FOR %%f IN (Names\CaseName_*.txt) DO TYPE %%f >> List_of_Accounts.txt

Thanks for any help

Upvotes: 0

Views: 1683

Answers (1)

patthoyts
patthoyts

Reputation: 33223

As the default token separator is whitespace the following works ok given your sample input:

for /f "tokens=1" %i in (em1.txt em2.txt) do echo '%i', >> output.txt
or to get a wildcard in there:

for %f in (em*.txt) do for /f "tokens=1" %i in (%f) do echo '%i', >> output.txt

Upvotes: 2

Related Questions