I have a input file of type .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. 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 )
Place repl.bat
in the same folder as the batch file or in a folder that is on the path.
type "file.txt" |repl " " "\r\n" x >"newfile.txt"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.