Get Current Date from TXT/LOG File RRS feed

  • Question

  • User1990996447 posted

    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
    From 'C:\Logs\BlahYYYY-MM-DDBlah.log'
    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?

    Monday, June 4, 2018 8:49 PM

All replies

  • User1138193213 posted

    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 off

    for /f "usebackq tokens=1-4 delims=/ " %%a in (`date /t`) do set TMPDATE=%%d-%%b-%%c

    logparser.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!

    Saturday, September 1, 2018 5:51 AM