从文件中提取文本(从 delim 到行尾)- BATCH

Extracting text (from delim to end of line) from file - BATCH

文本文件:

juicer test 1 2
next line
end

代码:

for /f "delims=test tokens=1*" %%A in (file.loc) do echo %%B

我得到了什么:

r test 1 2
xt line
ECHO is off.

预期结果:

test 1 2
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
rem The following settings for the source directory, destination directory, target directory,
rem batch directory, filenames, output filename and temporary filename [if shown] are names
rem that I use for testing and deliberately include names which include spaces to make sure
rem that the process works using such names. These will need to be changed to suit your situation.

SET "sourcedir=u:\your files"
SET "filename1=%sourcedir%\q65836459.txt"

SET "string=test"

FOR /f "usebackq delims=" %%a IN ("%filename1%") DO (
 SET "line=%%a"
 IF "!line:*%string%=!" neq "%%a" ECHO %string%!line:*%string%=!
)
GOTO :EOF