Splunk Search

remove a blank line from a file

abhayneilam
Contributor

Hi , I would like to remove a blank line from a file based on certain fields

If that field is blank, i will remove the whole record

Kindly help !!

Thanks
Abhay

Tags (2)
0 Karma

MHibbin
Influencer

This is a bit of an open-ended question, and if the following does not answer your question please provide some more details and examples.

I suspect that you mean that if a field for a certain events contains a NULL value (i.e. nothing), then you would like to exclude the whole event from the results. This is easily achievable by using the where command and the isnotnull() function. For example say I have the following search and results (where the fields have already been extracted):

sourcetype=myST | table field1, field2, field3

field1 | field2 | field3
foo    |  1234  | qwerty
bar    |        | ytrewq
blah   |  5678  | qywter

And you wish to remove any row where field2 does not contain a value, you could extend the search to the following:

sourcetype=myST | table field1, field2, field3 | where isnotnull(field2)

Which would give the following results:

foo    |  1234  | qwerty
blah   |  5678  | qywter

I hope this helps answer your question. If it does not, the following could be possible answers...

If you mean that there are blank lines at the end of each event, or there are events with no values what so ever, you could be experiencing issues with line-breaking/event-breaking. If this is the case, you should look at the following (this will not work on historically indexed data, and may require a re-index of data):

http://docs.splunk.com/Documentation/Splunk/5.0/Data/Indexmulti-lineevents
http://docs.splunk.com/Documentation/Splunk/5.0/admin/Propsconf

If you mean that your data sources are generating blank lines/fields and you wish to exclude these events, you should probably create a script that will read through and "modify" the output to meet your requirements using logical statements and funtions that strip out white space (e.g. such as python's strip() function).

For help on these points, please update your question with more details and examples

Hope this helps.

MHibbin

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 ...