Log Parser + how to use dynamic filelogdate

Jeff Harding 41 Reputation points
2023-03-28T16:04:29.4566667+00:00

I am trying to write a query in Log Parser 2.2 to dynamically fill in the LogFileDate field with todays date. I have to do this since W3C format doesn't allow for -iCheckPoint

From my research, I can use powershell and the get-date function:

E:"Log Parser 2.2"\LogParser.exe ""Select * from u_ex"+(get-date -format "yyMMdd")+"_x.log""

If I run this in powershell, it says Syntax Error: extra token after query '+'

If I just run ""Select * from u_ex"+(get-date -format "yyMMdd")+"_x.log"", it comes back with "Select * from u__ex230328_x.log", which is correct. Can I not run it inline?

Would it be easier to run it in command line with TO_STRING(SYSTEM__DATE(),'yyMMdd'

I'd like to schedule this eventually so not sure if PowerShell or CmdLine (via bat file) would be easier

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,381 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 45,091 Reputation points
    2023-03-28T19:08:25.88+00:00

    There's no need to use string concatenation operators to accomplish this.

    "Select * from u_ex$(get-date -format 'yyMMdd')x.log"
    
    

1 additional answer

Sort by: Most helpful
  1. MotoX80 31,656 Reputation points
    2023-03-28T19:11:30.32+00:00

    I found this cmd/bat example in my notes.

    **** Basic display ****
    logparser "SELECT  TO_LOCALTIME(TO_TIMESTAMP(date,time)) as [Local Time], cs-host, c-ip, cs-username,sc-status, cs-uri-stem, SUBSTR(cs-uri-query,0,50)  FROM 'E:\inetpub\LogFiles\ex%date:~12,2%%date:~4,2%%date:~7,2%.*' where c-ip = '162.109.77.72'  " -rtp:-1 -recurse
    
    

    For powershell you can set a variable or enclose the parameters in $() so that PS evaluates everything. (I think that will work. I don't have logparser installed on my laptop.)

    $parms = "Select * from u_ex"+(get-date -format "yyMMdd")+"_x.log"
    logparser.exe $parms
    logparser.exe $("Select * from u_ex"+(get-date -format "yyMMdd")+"_x.log") 
    
    0 comments No comments