Batch - copy lines after string was found

June 29, 2009 at 01:07:13
Specs: Windows XP
I am searching test_promweb.log.

Test_promweb.log:
sun 28.06.2009
C:\VMtriggers\Preb_script>del
C:\prebacweb\test\BLST_DNEV_RAZ_ARH.fmx
mon 29.06.2009
C:\VMtriggers\Preb_script>pcli
C:\prebacweb\test\br_zak.fmx

I am trying to search test_promweb.log and when I find date(todays date), then I wan't to copy and count some lines which starts with C:\prebacweb\test in c:\read_log.txt. for todays date, not for whole log!
In this example I want to copy only one line: C:\prebacweb\test\br_zak.fmx (date mon 29.06.2009).

My code:
@echo on

find "%date%" C:\test_promweb.log > Nul
If ErrorLevel 1 GoTo FALSE

:TRUE
Echo %date% was found in C:\test_promweb.log >> c:\read_log.txt
GoTo work

:FALSE
Echo %date% wasn't found in C:\test_promweb.log >> c:\read_log.txt
GoTo EXIT

:work
findstr /I /C:"Checked out revision" c:\test_promweb.log > nul >> c:\read_log.txt
findstr /I /E /C:"fmx" c:\test_promweb.log > nul >> c:\read_log.txt

For /F %%A in ('FindStr /I /B /C:C:\prebacweb test_promweb.log ^| Find /C "C:\prebacweb" ') Do Set counter1=%%A
For /F %%A in ('FindStr /I /B /C:C:\prebacweb\test test_promweb.log ^| Find /C "C:\prebacweb\test" ') Do Set counter2=%%A

echo %time% %date% >> c:\read_log.txt

echo counter1=%counter1%, counter2=%counter2%
pause

:EXIT

Thx for answers!


See More: Batch - copy lines after string was found

Report •


#1
June 29, 2009 at 18:09:49
if you have gawk for windows (see my sig)

BEGIN{
	date=strftime("%d.%m.%Y",systime())
}
$1 ~ /sun|mon|tue|wed|thu|fri|sat/{f=0}
$0 ~ date{f=1}
f && /prebacweb\\test/{
	print $0 > "c:\\read_log.txt"
} 

save as myscrpt.awk and on command line

C:\test>gawk -f test.awk logfile.txt

GNU win32 packages | Gawk


Report •
Related Solutions


Ask Question