Splunk Search

Removing rows from table based on more than one field

kxmorrr
Engager

Hi,

I am trying to filter out fields from a table based on its content, example:

LP. NAME SURNAME STREET CITY
1. Bob Smith mainst florida
2. Greg Obama secondaryst miami

I want to remove second row from table based on fact that it have "Greg" AND "Miami" in name and city fields.

So far I tried:
|search Name NOT "Greg" AND City NOT "Miami"
but it didnt work for me. Any ideas?

Labels (2)
0 Karma
1 Solution

PickleRick
SplunkTrust
SplunkTrust

Depends on what you want to get. But your

|search Name NOT "Greg" AND City NOT "Miami"

means something different that you want.

If you don't compare field names to a value (might be a wildcard), splunk treats it as an ordinary text to search. Also, if you don't specify other operations, you have implied AND, so your search is equal to

|search "Name" AND NOT "Greg" AND "City" AND NOT "Miami"

It's definitely not what you want.

You want (depending on the desired outcome)

| search Name!="Greg" AND City!="Miami"

 or maybe

| search Name!="Greg" OR City!="Miami"

Depending on whether you want to filter out one or both possibilities at the same time.

And remember that with splunk A!=B is not the same as NOT A=B

View solution in original post

PickleRick
SplunkTrust
SplunkTrust

Depends on what you want to get. But your

|search Name NOT "Greg" AND City NOT "Miami"

means something different that you want.

If you don't compare field names to a value (might be a wildcard), splunk treats it as an ordinary text to search. Also, if you don't specify other operations, you have implied AND, so your search is equal to

|search "Name" AND NOT "Greg" AND "City" AND NOT "Miami"

It's definitely not what you want.

You want (depending on the desired outcome)

| search Name!="Greg" AND City!="Miami"

 or maybe

| search Name!="Greg" OR City!="Miami"

Depending on whether you want to filter out one or both possibilities at the same time.

And remember that with splunk A!=B is not the same as NOT A=B

kxmorrr
Engager

I want to remove field if and only if both conditions are satisfied, this is when name is Greg and city is Miami, but keep the row if none or only one is satisfied, 

| search Name!="Greg" AND City!="Miami"

Removes all Gregs from the table, but I only want those living in Miami gone. 

0 Karma

PickleRick
SplunkTrust
SplunkTrust

Are you sure your field names are properly-cased? In splunk search values are case-insensitive but field names are case-sensitive.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...