Get Current Date from TXT/LOG File
Last post Sep 01, 2018 05:51 AM by robmcm
Jun 04, 2018 08:49 PM|Xebarsis|LINK
Just started using LogParser recently, and I'm new to SQL queries.
I'm trying to get LogParser to find a log file with today's date, then outputting specific contents of the file into a text document. For example:
Select Text INTO D:\LogParser\output\BlahYYYY-MM-DD.txt
where Text like '%exception%'
How do I get my query to search for today's date in the file name, while keeping the YYYY-MM-DD format, and output to a text file with the same date and format?
Sep 01, 2018 05:51 AM|robmcm|LINK
I'm not sure that I completely understand what you are trying to do, but the following batch file might help you discover what you need. (See the explanation below the batch file for more information.)
@echo offfor /f "usebackq tokens=1-4 delims=/ " %%a in (`date /t`) do set TMPDATE=%%d-%%b-%%clogparser.exe "SELECT cs(User-Agent) INTO '%TMPDATE%.txt' FROM '%TMPDATE%.log' WHERE cs(User-Agent) LIKE '%%MSIE%%'" -i:w3c -rtp:-1
As you can see, the batch file gets the current date and sets that in an environment variable, and that value is used to query the appropriate log file based on that date, and inserts the results into a text file with the same date.
I hope this helps!