[英]Replace all spaces with a new line in CMD
I have a input file of type .txt : 我有一个类型为.txt的输入文件:
// file.txt
The quick brown dog jumped over the lazy fox.
Basically I want to use this input file to produce an output file with each string quote-enclosed and on its own line in CMD. 基本上我想使用这个输入文件生成一个输出文件,每个字符串引用括起来并在CMD中自己的行。 Any ideas?
有任何想法吗?
Output should be like this: 输出应该是这样的:
'The'
'quick'
etc...
@echo off
set /p text=<file.txt
(for %%i in (%text%) do echo '%%i')>newfile.txt
I note now that the terms were supposed to be enclosed in single quotes - which the code below doesn't do. 我现在注意到这些术语应该用单引号括起来 - 下面的代码不能这样做。 It just does what the subject line asks and separates each term on a new line by itself.
它只是做主题行自己在新行上询问和分隔每个术语。
Here is a more robust solution that handles poison characters, and retains all characters in the file, and is far quicker on large files. 这是一个更强大的解决方案,可以处理有毒字符,并保留文件中的所有字符,并且在大文件上更快。
This uses a helper batch file called repl.bat
( preview as gist or download from dropbox ) 这使用名为
repl.bat
的帮助程序批处理文件( 预览为gist或从dropbox下载 )
Place repl.bat
in the same folder as the batch file or in a folder that is on the path. 将
repl.bat
放在与批处理文件相同的文件夹中或放在路径上的文件夹中。
type "file.txt" |repl " " "\r\n" x >"newfile.txt"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.