Getting Data In

how to add header field to an inputlookup CSV without header

wiggler
Explorer

Hi guys, I am wondering if it is possible to add a header field to search result if the CSV source doesn't have a header?

I know that props.conf is needed to setup but I am hoping that it can be done without making any change on the config.

Let say my CSV is something like this:

user1, google.com, 2002, 23:32:08

and if I do a search "| inputlookup filename.csv" it shows the results as a field name instead of the results.

so I want to have something like:

> username      website    hits date
> user1         google.com 2002 23:32:08

Thanks.

Tags (1)
1 Solution

woodcock
Esteemed Legend

If your file only has 1 line then the inputcsv will fail entirely so I am assuming that you did not mean that. If it has more than one line and is missing the header line such that inputcsv misinterprets the first line of data as the header, then you can do something like this:

| inputcsv eraseme.csv | transpose | transpose | fields - column | rename "row 1" AS year "row 2" AS time "row 3" AS domain "row 4" AS user | outputcsv eraseme.csv

The super-irritating this is that you cannot control the alphabetical sorting of the columns.

View solution in original post

woodcock
Esteemed Legend

If your file only has 1 line then the inputcsv will fail entirely so I am assuming that you did not mean that. If it has more than one line and is missing the header line such that inputcsv misinterprets the first line of data as the header, then you can do something like this:

| inputcsv eraseme.csv | transpose | transpose | fields - column | rename "row 1" AS year "row 2" AS time "row 3" AS domain "row 4" AS user | outputcsv eraseme.csv

The super-irritating this is that you cannot control the alphabetical sorting of the columns.

wiggler
Explorer

Pretty cool. thank you very much 🙂

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...