Difference between revisions of "For loop in CMD parsing entries in a TXT file"

From Tech-Wiki
Jump to: navigation, search
Line 5: Line 5:
 
  for %a in (host1 host2 host3) do Ping %a
 
  for %a in (host1 host2 host3) do Ping %a
  
 +
The same, but reading from file instead:
 
  for /F %a in (hosts.txt) do Ping %a
 
  for /F %a in (hosts.txt) do Ping %a
 +
 +
If your file contains spaces, then this amend would be required:
 +
for /F "tokens=* delims=," %a in (hosts.txt) do Ping %a

Revision as of 04:19, 18 May 2020

Back to Misc


for %a in (host1 host2 host3) do Ping %a

The same, but reading from file instead:

for /F %a in (hosts.txt) do Ping %a

If your file contains spaces, then this amend would be required:

for /F "tokens=* delims=," %a in (hosts.txt) do Ping %a