find/search specified word "Dostips" in last line

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mohdfraz
Posts: 69
Joined: 29 Jun 2011 11:16

find/search specified word "Dostips" in last line

#1 Post by mohdfraz » 29 Jun 2011 11:21

Hi,

I need a Dos batch file command to, find/search specified word "Dostips" in last line of specified c:\a.txt file and if found run 1.txt file if not then go to loop and keep monitoring file.

Thanks

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: find/search specified word "Dostips" in last line

#2 Post by !k » 29 Jun 2011 12:01

Code: Select all

@echo off &setlocal enableextensions
:loop
for /f "tokens=1,* delims=]" %%k in ('find /n /v "" a.txt') do (
echo "%%l"|findstr /c:"Dostips" >nul &&set find=Yes||set find=)
if not "%find%"=="Yes" (ping -n 2 127.0.0.1 >nul &goto :loop)
start 1.txt

mohdfraz
Posts: 69
Joined: 29 Jun 2011 11:16

Re: find/search specified word "Dostips" in last line

#3 Post by mohdfraz » 29 Jun 2011 12:19

!K

Wahoo,,, U r an expert. It worked great.

Please One more thing to make sure word is not missed, If it is possible that instead of only looking last line, If it can look for word "Dostips" in Last 10 lines of A.txt file? if match found run 1.txt other wise goto Loop and keep monitoring the file.

Thanks in Advance

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: find/search specified word "Dostips" in last line

#4 Post by !k » 29 Jun 2011 12:57

Code: Select all

@echo off &setlocal enableextensions
set "log=c:\a.txt"
:loop
ping -n 2 127.0.0.1 >nul
for /f "delims=[]" %%l in ('find /n /v "" "%log%"') do set /a line=%%l-10
if %line% LSS 0 set /a line=0
more +%line% "%log%" |findstr /c:"Dostips" >nul &&start 1.txt ||goto :loop

mohdfraz
Posts: 69
Joined: 29 Jun 2011 11:16

Re: find/search specified word "Dostips" in last line

#5 Post by mohdfraz » 29 Jun 2011 14:38

:) Wahoo, Impressive. You r the Star!!!

I searched the net but no luck!!
I gave this question on other forums but no reply.

But solved it in minutes.

Thank you very very much. God bless u all the time.

Post Reply