About "Read words separated by space in a batch script"
Posted: 30 Jan 2017 04:44
Hello! This is about DBenham's answer in SO here: http://stackoverflow.com/a/19121445.
The code is awesome because it does not treat comma as delimiter. However, even though there is an exclamation in the file, the character is not displayed.
Example.txt
Code.bat
Output:
What can be a remedy for it?
Meerkat
The code is awesome because it does not treat comma as delimiter. However, even though there is an exclamation in the file, the character is not displayed.
Example.txt
Code: Select all
Rock and Roll!
What am I doing in my laip?
Code.bat
Code: Select all
@echo off
setlocal disableDelayedExpansion
:: Define LF to contain a newline character
set LF=^
:: Above 2 blank lines are critical - DO NOT REMOVE
for /f "eol= tokens=*" %%A in (Example.txt) do (
set "ln=%%A"
setlocal enableDelayedExpansion
for %%L in ("!LF!") do for /f "eol= " %%W in ("!ln: =%%~L!") do echo %%W
endlocal
)
Output:
Code: Select all
Rock
and
Roll
What
am
I
doing
in
my
laip?
Meerkat