简体   繁体   English

过滤从Windows DOS批处理中的文件读取的文本

[英]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.

相关问题 从DOS / Windows批处理文件运行Sybase SQL命令 - Running Sybase SQL commands from DOS/Windows batch file 批处理Windows 7:循环读取文本文件 - batch windows 7: loop to read a text file 如何从第x行到第y行读取文件(dos / win批处理文件) - how to read a file from line x to line y (dos/win batch file) 当某些字段为空时,Windows批处理文件如何从分隔的文本文件中正确读取数据? - How can a Windows batch file read data correctly from a delimited text file when some fields are null? Windows批处理文件读取文本文件并将全部转换为大写 - Windows batch file read text file and convert all to uppercase Windows 批处理:从文本文件设置变量 - Windows Batch: Set Variables from Text File 在DOS / Windows批处理文件(.BAT)中,SET之后的REG命令“未知” - REG command after SET is “unknown” in DOS/Windows batch file (.BAT) 使用'>'在记事本中写入的批处理文件在dos窗口中显示'1>'。 - Batch file written in notedpad with '>' shows '1>' in dos windows. 在Windows 7中使用ActiveTcl 8.5在tcl脚本中运行DOS命令或批处理文件 - Running DOS command or batch file in tcl script in Windows 7 with ActiveTcl 8.5 升级Windows的DOS批处理文件 - Upgrading DOS Batch files for Windows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM