Splunk Search

How to trim the results

Laya123
Communicator

Hi,

After using search command I got the following output for XYZ field

/mrIWeb/Images/SE/2.1/lib/qstudio/qcreator/qcore/QWidget.js
/mrIWeb/Images/SE/2.0/source/js/SurveyEngine.js
/mrIWeb/Images/SE/1.7.1/lib/qstudio/qcreator/qcomponent/BtnMatrix.js
/mrIWeb/Images/SE/1.8/lib/qstudio/qcreator/qcomponent/DragnDrop.js

but I dont want my output like this,

I want to display my output like

/mrIWeb/Images/SE/2.1
/mrIWeb/Images/SE/2.0
/mrIWeb/Images/SE/1.7.1
/mrIWeb/Images/SE/1.8

is it possible can you help to resolve this

Thanks

Tags (1)
0 Karma
1 Solution

FritzWittwer_ol
Contributor

I would do it with an eval and Rex, something along the following addition to the search

... | rex field=XYZ "(?<XYZ_trimmed>(\/[^\/]*){4})\/.*"

should give you the desired trimmed result in the field XYZ_trimmed, see http://docs.splunk.com/Documentation/Splunk/6.1.5/SearchReference/Rex

View solution in original post

FritzWittwer_ol
Contributor

I would do it with an eval and Rex, something along the following addition to the search

... | rex field=XYZ "(?<XYZ_trimmed>(\/[^\/]*){4})\/.*"

should give you the desired trimmed result in the field XYZ_trimmed, see http://docs.splunk.com/Documentation/Splunk/6.1.5/SearchReference/Rex

Laya123
Communicator

Thank you so much

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!

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...