Splunk Search

How to extract data?

Contributor

Hello,

i am trying to extract from a search some data, and split the data into two fields with values.

So far i only managed to extract one field. How can i extract also the other?

Data Sample:

2010-01-20  16:55:45    0.0000  50.10.12.16 GP  GP_FOO  -   35  ja  -   19.1    AB  -   TST-00000   12355678    S12345678   FOOKey=5;FOOKeyM=0;

2010-01-20  16:56:45    0.0000  15.28.12.19 GP  GP_FOO  -   35  ja  -   49.1    AB  -   TST-00000   12345678    S12545678   FOOKey=10;FOOKeyM=3;

Here´s the search i am using so far:

index=idx_FOO myvariable="GP_FOO" | extract pairdelim=";", kvdelim="=;", auto=f

It delivers me the field "FOOKeyM"+value. But i also want "FOOKey" to get extracted. I don´t know any further. How can i achieve this?

Thomas

p.s. I don´t want to extract the fields in props or transform.conf. It´s only for a one time report.

Tags (1)
1 Solution

SplunkTrust
SplunkTrust

1) Are you sure Splunk wasnt extracting it automatically even without the extract command? I ask because Splunk always does foo=bar extraction automatically when it sees equal signs.

Although perhaps it was thrown off by the semicolon im not sure. Worth double checking cause if so, less is more.

2) If it really is just these fields it might be better to go with a standard rex command rather than trying to use extract. rex is a better tool across a wider range of situations, and the process of turning rex into a proper extraction is just a copy paste..

| rex "FOOkey=(?<FOOkey>.+);FooKeyM=(?<FOOkeyM>.+)"

View solution in original post

SplunkTrust
SplunkTrust

1) Are you sure Splunk wasnt extracting it automatically even without the extract command? I ask because Splunk always does foo=bar extraction automatically when it sees equal signs.

Although perhaps it was thrown off by the semicolon im not sure. Worth double checking cause if so, less is more.

2) If it really is just these fields it might be better to go with a standard rex command rather than trying to use extract. rex is a better tool across a wider range of situations, and the process of turning rex into a proper extraction is just a copy paste..

| rex "FOOkey=(?<FOOkey>.+);FooKeyM=(?<FOOkeyM>.+)"

View solution in original post

SplunkTrust
SplunkTrust

yea, i figured. (but for any other readers reading this thread note that in most cases 'foo=12 bar=21' will get autoextracted with no need for either rex nor extract. Here something throws it off, possibly the semicolon)

0 Karma

Contributor

p.s. No it doesn´t extract the data automatically. I was just using foo for the example here. Security, you know...;

0 Karma

Contributor

Ah, that works like a charm!
I was previously trying this:

| rex "(?i)^(?:[^\-]*\-){6}\d+\t\d+\t\w+\t(?P.+)"

But that only selects the whole FOOkey Terms.

Thank you Nick!

0 Karma

Splunk Employee
Splunk Employee

I don't think you should have a ; in your kvdelim just an "=", as such:

index=idx_FOO myvariable="GP_FOO" | extract pairdelim=";", kvdelim="=", auto=f

That should put you where you want to be.

Contributor

Sorry, that selects only the "FOOkeyM" part. i think Nick is right, and the best approach in this case is a regular expression.
But thank you.

0 Karma