我想我死了,已经进入蝙蝠文件地狱了。
我正在尝试处理如下所示的文本文件:
"N" "accounts" "General" no "0001"
"N" "accounts" "Customer" no "0002"
and so on
批处理文件如下所示:
setlocal EnableDelayedExpansion
set TGT=schctrl
set TMP=schctrl.tmp
copy %TGT% %TMP%
set NWOV=accounts inventory generalledger headoffice
for %%a in (%NWOV%) do (
for /f "tokens=2,5 delims= " %%D in ('findstr /i %%a %TMP%') do (
set M=%%E
set M=%M:"=%
echo %%D %%E %M%
)
)
我期待这里的 set 语句: set M=%M:"=% 去掉所有引号(它没有),当我运行它时,我得到这样的输出:
set M="1148"
set M=!M:"=!
echo "accounts" "1148"
我期待最后一个像这样:“accounts”“1148”1148,但最后一个字段丢失了。
我猜罪魁祸首是 for 循环和变量扩展,但我一直在努力解决这个问题,但尚未找到解决方案。
温柔点 - Windows /DOS 不是我的强项
蒂亚
奈杰尔。
当您打开
cmd
并运行 for /?
时。向下滚动到 Substitution and read the first line: [![enter image description here][1]][1] Therefore
%%Ewill contain quotes and
%%~E` 部分不包含引号。因此,只需更改代码中的元变量即可:
@echo off
set "TGT=schctrl"
set "TMP=schctrl.tmp"
copy "%TGT%" "%TMP%"
set "NWOV=accounts inventory generalledger headoffice"
for %%a in (%NWOV%) do (
for /f "tokens=2,5 delims= " %%D in ('findstr /i %%a %TMP%') do (
echo %%D %%~E %%E
)
)