开发者

MS DOS 'for' command to access file contents -- spaces

开发者 https://www.devze.com 2023-01-14 01:23 出处:网络
If a.txt contains a b c abc The command for /f %开发者_JAVA技巧x in (a.txt) do echo %x is printing a

If a.txt contains

a b c
abc

The command for /f %开发者_JAVA技巧x in (a.txt) do echo %x is printing

a
abc

What am I doing wrong?


for /f "tokens=*" %x in (a.txt) do @echo %x

The @echo will prevent the echo line from being printed

MS DOS 'for' command to access file contents -- spaces


for /f "delims=|" %i in (a.txt) do @echo %i

Inside "delims=|" you can use any character for the delimiter that is not part of the file



@echo off
setlocal
for /F "usebackq tokens=1-3 delims= " %%a IN ("a.txt") DO (
    if not "%%a"=="" echo.%%a
    if not "%%b"=="" echo.%%b
    if not "%%c"=="" echo.%%c
)
Tokens - the set of chars delimited by one of the delim char. You can specify many delim chars, i.e. delims= .,

0

精彩评论

暂无评论...
验证码 换一张
取 消