FOR /F (Windows loop) How to make delims not singl

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
xcislav
Posts: 1
Joined: Wed Dec 22, 2010 4:27 am

FOR /F (Windows loop) How to make delims not singl

Post by xcislav » Wed Dec 22, 2010 4:29 am

In loop FOR /F there is very good block separator delims= tokens=. But
I'm frustrated that delims can hold only 1 symbol. But I want to extract
from list only machines which run on 'Windows 2000' like:
FOR /F "delims='Windows 2000' tokens=2" %%i in (genlist.txt) do systeminfo /s %%i

File genlist.txt was produced by listing all the computers on network:
@echo off
FOR /F %%i in ('net view ^| find ""') do echo %%i

User avatar
jvierra
Posts: 13571
Joined: Tue May 22, 2007 9:57 am
Contact:

FOR /F (Windows loop) How to make delims not singl

Post by jvierra » Wed Dec 22, 2010 6:12 am

delims=xxx - specifies a delimiter set. This replaces the default delimiter set of space and tab.


Delimiters in 'delim' argument are a collection of characters used to break a line into tokens like spaces, commas or semi-colons. They are treated one character at a time.

delim=,.;:|!{}[]

delim should not be used to try and match string in a file. Use FINDSTR to find lines that contain a specific string.

User avatar
jvierra
Posts: 13571
Joined: Tue May 22, 2007 9:57 am
Contact:

FOR /F (Windows loop) How to make delims not singl

Post by jvierra » Thu Dec 23, 2010 2:46 am

Here is a better way to get the matching OS types from the network:

Code: Select all

wmic /node:ws001,ws002,alpha  os get csname,name | find /i "Windows 2000"
wmic /node:@"c:computers.txt"  os get csname,name | find /i "Windows 2000"
wmic /node:@"c:computers.txt"  os get csname,name | find /i "Windows 2000" /format:csv
wmic /OUTPUT:output.csv /node:@servers.txt OS get csname,name /format:csv
wmic /node:@"c:computers.txt"  os get csname,name | find /i "Windows 2000" /format:rawxml.xsl
wmic /node:@"c:computers.txt" path win32_operatingsystem where "name like '%2000%'" get csname,name

http://support.microsoft.com/servicedes ... eusage.asp

jvierra2010-12-23 10:01:34

Locked