Splunk Search

Replace a character with a linebreak in table results

cmak
Contributor

I would like to replace all characters "___" in a certain field with a linebreak in my Table module.

I am currently using the following code

eval n=replace(my_field, "___", "\n")

It does not treat \n as a newline. How do I let Splunk know I want a linebreak

Tags (2)
0 Karma
1 Solution

mmol
Explorer

The links to the 'other' questions/answers do not work anymore.

But what does work is:

| eval n=replace(my__field, "___", "
")

 

 So literally add a newline to your code.

It is silly to need to do it in this way. Why are \n and similar characters as replacements not supported, while they are supported in the pattern. The replace function should also allow other options like replace only one occurrence or all occurrences (learn a bit from the Perl language I guess...)

afreidin
New Member

If this helps anyone, I solved this using a streamstats which always resets:

...
| streamstats reset_before="1=1" list(mvfield) as mvfield
| table mvfield
0 Karma

ZacEsa
Communicator

The second answer here http://splunk-base.splunk.com/answers/41691/add-newline-into-table-cell

Which says use split. That worked for me. Rex mode=sed doesn't work for me.

0 Karma

Ayn
Legend

Thanks, nice catch. Fixed.

0 Karma

cmak
Contributor

Thanks, just as a note, the mvjoin requires the eval statement in front of it.

0 Karma

Ayn
Legend

Indent code blocks with 4 spaces on each line (or click the "1010101" button which does this for you). This will make code show up properly on the site. I fixed this for you this time though.

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

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...