Freigeben über


Logparser Scenario 7:Searching specific column names from a CSV file

This blog entry is a continuation of the KB Article https://support.microsoft.com/?id=910447.

Scenario 7: Searching specific column data from a CSV file using Logparser

Let's say you have a CSV (comma separated value) text file as follows...

abc,abd,ac,rd,abe,f,g
1,2,3,4,5,6,7
3,2,3,4,5,2,5
3,4,5,7,3,5,7

And then, you want the columns with the following names... (abc, abd and abe) so that you can get the following output...

abc,abd,abe
1,2,5
3,2,5
3,4,3

Answer: You can use the following query

logparser "Select abc, abd, abe from C:\myfile.txt" -i:CSV

And you should get the following output...

image

You can also use EXTRACT_TOKEN (in case it is not a CSV and some other character separated file, for example Dash (-) separated values... The command to do that would be...

LogParser "Select EXTRACT_TOKEN(TEXT, 0, ',') as ONE, EXTRACT_TOKEN(TEXT, 1, ',') as TWO, EXTRACT_TOKEN(TEXT, 4, ',') as THREE from C:\MyFile.txt" -i:Textline

The output is quite similar... (except the header). But anyways, you get the idea Smile

image 

Hope that helps,
Rahul

Share this post :

Quote of the day:
The best way to predict the future is to invent it. - Alan Kay