# Solved: Getting a value with a .bat script



## NZ4Ever (Jan 11, 2009)

Im trying to get a value (IP address) from a W3C logfile (kinda like a text file). This is what I have so far but with no luck:

Set filename=ex%date:~-2,4%%date:~-10,2%%date:~-7,2%.log

For /F "tokens=2 delims=: . " %%A in ('E:\WINDOWS\system32\LogFiles\MSFTPSVC6141885\%filename%') do (Set ip=%%A)

and the log file looks like:

# Software: Microsoft Internet Information Services 6.0
# Version: 1.0
#Date: 2009-01-10 20:58:16
#Fields: time c-ip cs-method cs-uri-stem sc-status sc-win32-status 
20:58:16 *10.10.1.111* [25]USER anonymous 331 0

so the IP adress is on the 4th line second column (10.10.1.111)

any feedback would be appreciated!


----------



## TheOutcaste (Aug 8, 2007)

Welcome to TSG!


```
Set filename=ex%date:~-2,4%%date:~-10,2%%date:~-7,2%.log
For /F "skip=4 tokens=2 delims= " %%A in ('Type %windir%\system32\LogFiles\MSFTPSVC6141885\%filename%') Do Set ip=%%A
```
If there is any chance the path\filename will contain a space, use this instead (changes in red, additions in blue):

```
Set filename=ex%date:~-2,4%%date:~-10,2%%date:~-7,2%.log
For /F "[COLOR=Blue]usebackq[/COLOR] skip=4 tokens=2 delims= " %%A in ([COLOR=Red][B]`[/B][/COLOR]Type [COLOR=Blue][B]"[/B][/COLOR]%windir%\system32\LogFiles\MSFTPSVC6141885\%filename%[COLOR=Blue][B]"[/B][/COLOR][COLOR=Red][B]`[/B][/COLOR]) Do Set ip=%%A
```
HTH

Jerry


----------



## NZ4Ever (Jan 11, 2009)

Perfect, hit the nail right on the head!! Thanks a lot for your help


----------



## TheOutcaste (Aug 8, 2007)

You're Welcome!

If your issue has been resolved you (and ONLY you) can mark this thread Solved by using the Mark Solved button at the Top Left of this thread (above the first post) 










Jerry


----------

