Splunk Search

extract a field from csv file

harshal_chakran
Builder

Hi,

I have a CSV file, which after indexing looks like this

"data1","12-13",y,20,1,"31.034483"
"data1","12-13",y,20,1,"31.034483"
"data1","12-13",y,20,2,45
"data1","12-13",y,20,3,"31.372549"
"data1","12-13",y,20,4,20

I have written a rex command to get the last column values in a table, but not able see all the variables, as some of it is in ""(double quotes) and some not as well some has decimal points.
My rex command is:-

sourcetype=xyz|search data1|rex "(?i)^(?:[^,]*,){5}(?P<FIELDNAME>.+)"|table FIELDNAME

I want the table to be without double quotes ,as shown below:-

31.034483
31.034483
45
31.372549
20

Please Help...!!!

Tags (4)
0 Karma
1 Solution

Ayn
Legend

If you want to match the last field the best approach imho is to anchor your match against the end of the line, not against how many fields are before the last one. This regex should work:

"?([\d.]+)"?$

View solution in original post

0 Karma

Ayn
Legend

If you want to match the last field the best approach imho is to anchor your match against the end of the line, not against how many fields are before the last one. This regex should work:

"?([\d.]+)"?$
0 Karma

harshal_chakran
Builder

Superb..!!!It worked!!
Thanks Ayn...

0 Karma

Ayn
Legend

... | rex "\"?(?<myvalue>[\d.]+)\"?$" | table myvalue

0 Karma

harshal_chakran
Builder

Hi Ayn,
Can you please tell me how to put this regex, as I am new to it. Its very hard for me to understand.

0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...