0

I want to print the policy name which is "My Default Policy". I am using the following command, however, this print only "My" as my delimiter is a space. How do i make a new line as the delimiter?

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)
Sandy
  • 35
  • 1
  • 7
  • Maybe [this post](http://www.dostips.com/forum/viewtopic.php?t=6471) will help you. And [this](http://stackoverflow.com/questions/15641301/new-line-as-a-delimeter-of-for-loop) too. (possible duplicate?) – Sangbok Lee Mar 08 '17 at 06:46

1 Answers1

1

There is no need to create a temporary file. Read 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)

Here

JosefZ
  • 28,460
  • 5
  • 44
  • 83