Yet Another FOR /F Question

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alleypuppy
Posts: 82
Joined: 24 Apr 2011 19:20

Yet Another FOR /F Question

#1 Post by alleypuppy » 10 Nov 2011 18:21

Hi all,

I have another FOR /F question. I want to know how to extract the contents of one line of the results of a FOR /F command. For example, I want to get the host name of the computer with this IP, so I use this command:

Code: Select all

FOR /F "TOKENS=1" %a IN ('NBTSTAT.EXE -a 192.168.1.68') DO @ECHO %a
The results are as follows:

Code: Select all

Local
Node
NetBIOS
Name
---------------------------------------------
DELL-PC
DELL-PC
WORKGROUP
WORKGROUP
WORKGROUP
..__MSBROWSE__.<01>
MAC
I want to extract the first occurrence of "DELL-PC" from this list. Is this possible?

Thanks for any help!

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Yet Another FOR /F Question

#2 Post by Ed Dyreen » 11 Nov 2011 04:45

'

Code: Select all

@echo off

set "$t="
::
FOR /F "skip=5 TOKENS=1" %%? IN (
   'NBTSTAT.EXE -a 192.168.1.68'
) DO if not defined $t (
   set "$t=%%~?"
)
echo.$t=%$t%_

pause
exit /b
To think you almost had it right :)

alleypuppy
Posts: 82
Joined: 24 Apr 2011 19:20

Re: Yet Another FOR /F Question

#3 Post by alleypuppy » 11 Nov 2011 12:11

Ed Dyreen wrote:To think you almost had it right :)
Haha almost!

The code works perfectly! :) I had to change the skip number from 5 to 8 though. Thanks again!

Post Reply