[英]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. 我正在尝试读取多个.txt文件的内容,并将每个文件的内容输出到单个文件中。 The hitch is that the .txt files I'm reading are the email address I want, and then a tab. 问题是,我正在阅读的.txt文件是我想要的电子邮件地址,然后是一个标签。 The single output file I'd like a just have the email address enclosed in quotes. 我想要的单个输出文件只是用引号括起来的电子邮件地址。
So the input file will be 所以输入文件将是
email1@test.com{tab}
email2@test.com{tab}
and the output should be 输出应该是
'email1@test.com',
'email2@test.com',
'email3@test.com',
'email4@test.com',
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. 我如何制作DO以便至少它会删除标签,并且奖励积分会添加引号和逗号。
FOR %%f IN (Names\CaseName_*.txt) DO TYPE %%f >> List_of_Accounts.txt
Thanks for any help 谢谢你的帮助
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.