0

This is a simple batch file that should run through a file (PingList_Results.txt) and pull out any line that matches the regex (IPv4 Addy) but it isn't working. I'm sure the issue is simple but I don't see it. Thanks!

Sample PingList_Results.txt:

Pinging 10.10.10.11 with 32 bytes of data: Reply from 10.10.10.11: bytes=32 time=62ms TTL=54

Ping statistics for 10.10.10.11: Packets: Sent = 1, Received = 1, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 62ms, Maximum = 62ms, Average = 62ms

Pinging 192.168.1.50 with 32 bytes of data: Reply from 192.168.1.50: bytes=32 time=61ms TTL=120

Ping statistics for 192.168.1.50: Packets: Sent = 1, Received = 1, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 61ms, Maximum = 61ms, Average = 61ms

Batch File:

@echo off

SET LOGFILE=PingList_Results.txt

FOR /F "tokens=*" %%A IN ('FINDSTR /R "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" %LOGFILE%') DO (ECHO.%%A)
Mark
  • 3,609
  • 1
  • 22
  • 33
  • _but it isn't working_ isn't very specific. What you get and what do you expect? – jeb Oct 08 '13 at 20:51
  • It returns nothing. I was expecting a match to be returned. If I remove the {1,3} it does match but instead of returning the match, it returns the whole line. – EntertainMyMind Oct 08 '13 at 20:58
  • You could read [What are the undocumented features and limitations of the Windows FINDSTR command?](http://stackoverflow.com/q/8844868/463115) for the most exact description of `findstr` – jeb Oct 08 '13 at 21:01
  • A helper batch file called `repl.bat` will give you better regexp and without the many bugs of `findstr`. It uses built in WSH features of Windows - You can get it from here: http://www.dostips.com/forum/viewtopic.php?f=3&t=3855 – foxidrive Oct 09 '13 at 00:40

2 Answers2

1

FINDSTR doesn't have {#,#} support, instead it is trying to match those characters literally - try the following instead:

@echo off

SET LOGFILE=PingList_Results.txt

FOR /F "tokens=*" %%A in ('FINDSTR /R "[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*" %LOGFILE% ') DO (ECHO %%A)

This effectively does the same thing, but doesn't require {1,3} where [0-9]* represents zero or more matches.

Sourced from this question.

Community
  • 1
  • 1
tyler
  • 26
  • 2
  • Thanks, this is what I ended up doing. I was just wanting the further validation so 1234.1.1.1 would NOT match. It's cool though, this will get the simple job done. – EntertainMyMind Oct 09 '13 at 16:18
0

see: http://ss64.com/nt/findstr.html

so far I have this:

FINDSTR /R "([0-9].[0-9].[0-9].[0-9])" %LOGFILE%

But I can't figure out how to just output the found text.

I don't think {1,3} is supported in findstr.

Derek
  • 7,615
  • 5
  • 33
  • 58
  • You're right, it appears to not take {1,3}. It also returns the entire line instead of just the match... – EntertainMyMind Oct 08 '13 at 20:57
  • From: http://stackoverflow.com/questions/14363981/using-findstr-length-in-batch it seems findstr doesn't support doing just the match. You are probably going to want to use something else. Sad, because findstr is built in. – Derek Oct 08 '13 at 20:59