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.
This topic is 13 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
xcislav
Posts: 1
Last visit: Wed Dec 22, 2010 3:29 am

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

Post by xcislav »

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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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
This topic is 13 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked