Splunk Search

Remove spacing from records after inputlookup

moinyuso96
Path Finder

The contents of my lookup file, test12345.csv is shown below.

ProductNumber,SerialNumber,StatusDateTime,Status

"A12345 ","MA00000001 ","2021-08-31 01:30:47 ","SHIPPED "

 

There is some space found "   " at the end of each record. The inputlookup would capture all the records with a spacing at the end which disrupts my joins to work properly. Is there anyway I can remove the spacing at the end of each record after using inputlookup?

ProductNumber =A12345

SerialNumber =MA00000001

StatusDateTime =2021-08-31 01:30:47

Status=SHIPPED

Labels (2)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @moinyuso96,

inside square brackets:

 ... 
|  join type=left ProductNumber Serial [ 
     | inputlookup test12345.csv|  rename SerialNumber as Serial
     | rex field=ProductNumber "(?<ProductNumber>.*)\s+$"
     | rex field=SerialNumber "(?<SerialNumber>.*)\s+$"
     | rex field=StatusDateTime "(?<StatusDateTime>.*)\s+$"
     | rex field=Status "(?<Status>.*)\s+$"
     ] 
| ...

Remember only one thing:

in this case, you have the problem of space in each field, so you have to modifiy fields using regexes or evals, but usually you can use the lookup command instead the join (the lookup command is a left join with a lookup).

In other words, remeber that Splunk isn't an SQL DB, so use join only when you haven't any other solution, because it's a very slow command.

For this reason, I'd try to solve the problem in the lookup, eventually modifying values in lookup.

I don't know how lookup is generated but you could correct the values in the lookup using a search, eventually to schedule.

Something like this:

| inputlookup test12345.csv
| rex field=ProductNumber "(?<ProductNumber>.*)\s+$"
| rex field=SerialNumber "(?<SerialNumber>.*)\s+$"
| rex field=StatusDateTime "(?<StatusDateTime>.*)\s+$"
| rex field=Status "(?<Status>.*)\s+$"
| table ProductNumber SerialNumber StatusDateTime Status 
| outputlookup test12345.csv

In this way, you can use a simpler lookup command:

| index=your_index
| lookup test12345.csv ProductNumber SerialNumber AS Serial OUTPUT StatusDateTime Status
| ...

Ciao.

Giuseppe

View solution in original post

moinyuso96
Path Finder

Hi @gcusello , thanks for answering.

However, I am not really sure where to insert the queries you gave me. Currently I am still have issues with the joins and inputlookup.

My join and inputlookup query is as follows:

 

 ... |  join type=left ProductNumber Serial [ | inputlookup test12345.csv|  rename SerialNumber as Serial] | ...

 

 




0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @moinyuso96,

inside square brackets:

 ... 
|  join type=left ProductNumber Serial [ 
     | inputlookup test12345.csv|  rename SerialNumber as Serial
     | rex field=ProductNumber "(?<ProductNumber>.*)\s+$"
     | rex field=SerialNumber "(?<SerialNumber>.*)\s+$"
     | rex field=StatusDateTime "(?<StatusDateTime>.*)\s+$"
     | rex field=Status "(?<Status>.*)\s+$"
     ] 
| ...

Remember only one thing:

in this case, you have the problem of space in each field, so you have to modifiy fields using regexes or evals, but usually you can use the lookup command instead the join (the lookup command is a left join with a lookup).

In other words, remeber that Splunk isn't an SQL DB, so use join only when you haven't any other solution, because it's a very slow command.

For this reason, I'd try to solve the problem in the lookup, eventually modifying values in lookup.

I don't know how lookup is generated but you could correct the values in the lookup using a search, eventually to schedule.

Something like this:

| inputlookup test12345.csv
| rex field=ProductNumber "(?<ProductNumber>.*)\s+$"
| rex field=SerialNumber "(?<SerialNumber>.*)\s+$"
| rex field=StatusDateTime "(?<StatusDateTime>.*)\s+$"
| rex field=Status "(?<Status>.*)\s+$"
| table ProductNumber SerialNumber StatusDateTime Status 
| outputlookup test12345.csv

In this way, you can use a simpler lookup command:

| index=your_index
| lookup test12345.csv ProductNumber SerialNumber AS Serial OUTPUT StatusDateTime Status
| ...

Ciao.

Giuseppe

gcusello
SplunkTrust
SplunkTrust

Hi @moinyuso96,

you have two ways:

  • the trim function in the eval command,
  • the regex.

using trim

| eval ProductNumber=trim(ProductNumber)
| eval SerialNumber=trim(SerialNumber)
| eval StatusDateTime=trim(StatusDateTime)
| eval Status=trim(Status)

using regex you have to add a row for each field:

| rex field=ProductNumber "(?<ProductNumber>.*)\s+$"
| rex field=SerialNumber "(?<SerialNumber>.*)\s+$"
| rex field=StatusDateTime "(?<StatusDateTime>.*)\s+$"
| rex field=Status "(?<Status>.*)\s+$"

Ciao.

Giuseppe

Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...