Splunk Search

How to read and write data to CSV lookup?

sbimizry
Engager

Hi, I must write and read data from lookup files.

Example:
cn,srcip,destip,owner
"Canada","207.188.75.136","192.1.104.10","user1"
"USA","62.249.72.118","192.168.1.11","user2"

and I tried to read data using | lookup file cn AS cn | table cn`but it did not work.
and this too
| lookup file cn OUTPUT cn`.

What should I do?

0 Karma
1 Solution

sheamus69
Communicator

If all you want to do is read the contents of the lookup try the inputlookup command.

For example,

|inputlookup file.csv

will list the entire contents of the lookup. You can search for a specific entry in the lookup using:

|inputlookup file.csv | search fieldname=whatever

To perform a lookup against the csv during a search would use the lookup command, like:

[main search] | lookup file.csv fieldname OUTPUT otherfieldnames|...

To write to a lookup you would use outputlookup.

For example:

|inputlookup file.csv|eval cn=if(cn=="something","something else",cn)|outputlookup file.csv

Will perform the lookup, and will change an entry in the field cn if it contains a specific value, and will then overwrite the original lookup (it is always advisable to test the results before performing this overwrite as errors can be embarrassing to fix).

Hope this helps,

Sheamus

View solution in original post

0 Karma

sheamus69
Communicator

If all you want to do is read the contents of the lookup try the inputlookup command.

For example,

|inputlookup file.csv

will list the entire contents of the lookup. You can search for a specific entry in the lookup using:

|inputlookup file.csv | search fieldname=whatever

To perform a lookup against the csv during a search would use the lookup command, like:

[main search] | lookup file.csv fieldname OUTPUT otherfieldnames|...

To write to a lookup you would use outputlookup.

For example:

|inputlookup file.csv|eval cn=if(cn=="something","something else",cn)|outputlookup file.csv

Will perform the lookup, and will change an entry in the field cn if it contains a specific value, and will then overwrite the original lookup (it is always advisable to test the results before performing this overwrite as errors can be embarrassing to fix).

Hope this helps,

Sheamus

0 Karma

sbimizry
Engager

I did it... [main search] | lookup file.csv fieldname OUTPUT otherfieldnames|... ... not worked

0 Karma

sheamus69
Communicator

What specifically are you trying to do with the lookup? Can you give an example?

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...