1

I have multiple TraceRT log files containing 30 hops. I'm only looking for similar IP (ex. 192.168.1) and would like to log it on one file with: 1) Successful: %IP% found in %Filename% 2) Fail: Specified IP not found in %Filename%

I'm trying to use:

rem************************************************************
:START

@ ECHO OFF

rem US date
set YEAR=%DATE:~10,4%
set MONTH=%DATE:~4,2%
set DAY=%DATE:~7,2%

rem US hour
set HOUR=%TIME:~0,2%
set MIN=%TIME:~3,2%
set SEC=%TIME:~6,2%
set HUNDREDS=%TIME:~9,2%
set HOURMIN=%HOUR%%MIN%

rem Make sure that hour has two digits
IF %HOUR% GEQ 10 goto twoh
set HOUR1=%TIME:~1,1%
set TWOHOUR=0%HOUR1%
goto fulltid

:twoh
set TWOHOUR=%HOUR%

:fulltid
set FULLTIME=%TWOHOUR%'%MIN%'%SEC%'%HUNDREDS%
set FTIME=%TWOHOUR%:%MIN%:%SEC%


@echo off & setLocal EnableDELAYedeXpansion
findstr /m "192.168.1" *.txt > FILENAME 
echo on
for /f "tokens=*" %%a in (*.txt ^| find "192.168.1") do (
IF %%a neq %%b (
echo Suscessful: %%a  %FILENAME%  >> Log%YEAR%%MONTH%%DAY%.txt
) ELSE (
echo Fail: Specified IP not found in %FILENAME% >> Log%YEAR%%MONTH%%DAY%.txt
)
)

goto START

rem************************************************************
Nat Ritmeyer
  • 5,634
  • 8
  • 45
  • 58
Prokotok
  • 11
  • 2
  • There is no `%%b`, as you have only one token: `*` – Stephan Aug 26 '15 at 06:48
  • instead of messing with local date/time formats, I strongly recommend an locale independent approach [like this](http://stackoverflow.com/a/18024049/2152082) – Stephan Aug 26 '15 at 09:33

1 Answers1

0
  1. You have specified an invalid pipe | find. You cannot pipe (a) text file(s) into a command.
    Either provide the file(s) as argument(s) to find, or use redirection (this works for a single file only but not for multiple ones nor */? patterns though).
  2. You are using for /f not correctly.
    It looks as if you wanted to parse the output of find. To accomplish that, but you must enclose the command within single-quotes '. Type for /? and see the help text for more details.

The following line of code should work:

    for /f "tokens=*" %%a in ('find "192.168.1" *.txt') do (

To get current date and time, I strongly recommend to read variables %DATE% and %TIME% once only and within a single line! Otherwise you might run into problems, especially concerning the fractional seconds, which might not be equal between consecutive expansions.

To ensure %HOUR% to have two digits, you simply need to use set HOUR=0%HOUR% then set HOUR=%HOUR:~-2%.

Since a one-digit %HOUR% is prefixed by a space here, you can have it even simpler (thanks for your comment, @Stephan!) by just replacing the space by a zero: set HOUR=%HOUR: =0%.

Community
  • 1
  • 1
aschipfl
  • 33,626
  • 12
  • 54
  • 99
  • 1
    here is an easier "two digit hour trick": `set "hour=%hour: =0%"` (replace the space with a zero) – Stephan Aug 26 '15 at 07:03