新行作为for循环批处理脚本中的分隔符

时间:2017-03-08 06:32:41

标签: batch-file

我想打印的政策名称是"我的默认政策"。我使用以下命令,但是,此打印仅仅是#34;我的"因为我的分隔符是一个空格。如何将新行作为分隔符?

reg query "HKEY_LOCAL_MACHINE\Software\McAfee\DLP\Agent\Properties\Policy" | find "PolicyName" > tmp.txt
for /F "tokens=3 delims= " %%f in (tmp.txt) do (echo "Policy Name:" %%f >> C:\mcafee.txt)

1 个答案:

答案 0 :(得分:0)

无需创建临时文件。阅读FOR /F - Loop through the output of a command

for /F "tokens=2,*" %%f in ('
    reg query "HKLM\Software\McAfee\DLP\Agent\Properties\Policy" ^| find /I "PolicyName"
  ') do (echo "Policy Name:" %%g >> C:\mcafee.txt)

这里