We are excited to announce that the IIS.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

Get Current Date from TXT/LOG FileRSS

1 reply

Last post Sep 01, 2018 05:51 AM by robmcm

  • Get Current Date from TXT/LOG File

    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
    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?

  • Re: Get Current Date from TXT/LOG File

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

    Robert McMurray [MSFT]