OK, this command works great, but I now have a request to have the output file names be exactly like the input file names. I tried a couple of things but kept getting errors. How would you modify the TO clause to do that?
logparser -i:TEXTLINE "SELECT LogFilename, '040207_12-35-23', Text FROM C:\Program\u0020Files\LogParser2.1\Logs\*.log TO *_*.txt WHERE Text LIKE '%02:00%:%' or Text LIKE '%02:01%:%' " -o:CSV
I'm assuming that you want the filename to be the same, but a different folder...
logparser -i:TEXTLINE "SELECT EXTRACT_TOKEN(LogFilename, -1, '\\'), Text FROM C:\Program\u0020Files\LogParser2.1\Logs\*.log TO C:\MyOtherFolder\* WHERE Text LIKE '%02:00%:%' or Text LIKE '%02:01%:%' " -o:CSV
EXTRACT_TOKEN is a pretty useful function you can use to "break" a string into substrings, given a separator.
In this case, you're saying that you want the last (-1) token that comes out of breaking the LogFilename field into tokens separated by the '\' character; i.e. the filename.
------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"
You're right, if the filename is C:\Program Files\LogParser2.1\Logs\Test.log, then the filename would be index n.4; however, if you change your path (navigating folders up or down), then you'll have to change the index...so it's easier to say "last index"
(i.e. -1), which works for every possible path (both C:\test.log and C:\folder1\folder2\folder3\folder4\folder5\folder6\folder7\test.log).
------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"
Thanks for the clarification. These 2 examples would be useful to add to the Help file or Knowledge Base so people can understand the many ways this powerful token can be used.
Anonymous
6623 Posts
Re: How to Run the same LogParser command for all the log files in a directory?
Feb 10, 2004 08:56 PM|LINK
OK, this command works great, but I now have a request to have the output file names be exactly like the input file names. I tried a couple of things but kept getting errors. How would you modify the TO clause to do that?
logparser -i:TEXTLINE "SELECT LogFilename, '040207_12-35-23', Text FROM C:\Program\u0020Files\LogParser2.1\Logs\*.log TO *_*.txt WHERE Text LIKE '%02:00%:%' or Text LIKE '%02:01%:%' " -o:CSV
Anonymous
6623 Posts
Re: How to Run the same LogParser command for all the log files in a directory?
Feb 10, 2004 09:12 PM|LINK
I'm assuming that you want the filename to be the same, but a different folder...
logparser -i:TEXTLINE "SELECT EXTRACT_TOKEN(LogFilename, -1, '\\'), Text FROM C:\Program\u0020Files\LogParser2.1\Logs\*.log TO C:\MyOtherFolder\* WHERE Text LIKE '%02:00%:%' or Text LIKE '%02:01%:%' " -o:CSV
EXTRACT_TOKEN is a pretty useful function you can use to "break" a string into substrings, given a separator.
In this case, you're saying that you want the last (-1) token that comes out of breaking the LogFilename field into tokens separated by the '\' character; i.e. the filename.
------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm"
Anonymous
6623 Posts
Re: How to Run the same LogParser command for all the log files in a directory?
Feb 10, 2004 10:51 PM|LINK
Thanks, Gabriele. That works just fine!
I am curious as to why you use -1 in the EXTRACT_TOKEN function and not 4 to get the filename.
If the LogFilename is:
C:\Program Files\LogParser2.1\Logs\Test.log
I am thinking that:
index 1 = Program (since that's the first \)
index 2 = LogParser2.1 (since that's the second \)
index 3 = Logs (since that's the third \)
index 4 = Test.log
Anonymous
6623 Posts
Re: How to Run the same LogParser command for all the log files in a directory?
Feb 11, 2004 03:17 PM|LINK
You're right, if the filename is C:\Program Files\LogParser2.1\Logs\Test.log, then the filename would be index n.4; however, if you change your path (navigating folders up or down), then you'll have to change the index...so it's easier to say "last index" (i.e. -1), which works for every possible path (both C:\test.log and C:\folder1\folder2\folder3\folder4\folder5\folder6\folder7\test.log).
------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm"
Anonymous
6623 Posts
Re: How to Run the same LogParser command for all the log files in a directory?
Feb 11, 2004 03:25 PM|LINK
Thanks for the clarification. These 2 examples would be useful to add to the Help file or Knowledge Base so people can understand the many ways this powerful token can be used.