Getting Data In

How to replace line breaks with delimiters?

paulalbert11
Explorer

I'm trying to replicate other threads that show how to replace line breaks with delimiters. This search is not working.

| ldapsearch domain=ED search="(&(objectClass=eduPerson)(weillCornellEduCWID=paa2013))" attrs="weillCornellEduCWID,o" 
| eval o1 = replace (o, "[\\n\\r]+","|")
| eval o2 = replace (o, "[\n\r]","|")
| table weillCornellEduCWID, o, o1, o2

Any ideas? See screenshot below..

alt text

Tags (2)
0 Karma
1 Solution

vasanthmss
Motivator

try something like this,

your base search.... | eval o1=o  |nomv o1 | rex mode=sed field=o1 "s/\n/|/g" 
V

View solution in original post

vasanthmss
Motivator

try something like this,

your base search.... | eval o1=o  |nomv o1 | rex mode=sed field=o1 "s/\n/|/g" 
V

plimpach
Explorer

does exactly what I needed, and much simpler
than the replace function I was trying to get to work.

0 Karma

paulalbert11
Explorer

It works like a charm. Thanks!

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Does this work?

| ldapsearch domain=ED search="(&(objectClass=eduPerson)(weillCornellEduCWID=paa2013))" attrs="weillCornellEduCWID,o" 
 | eval o1 = replace (o, "[\r\n]+","|")
 | eval o2 = replace (o, "\n","|")
 | table weillCornellEduCWID, o, o1, o2
0 Karma

paulalbert11
Explorer

Thanks for your response, somesoni2. Unfortunately, no. When I run the query, I just get blanks in the o1 and o2 fields.

0 Karma

somesoni2
SplunkTrust
SplunkTrust

So, if I'm not wrong, the field o is a multivalued field and you just want to make it linear with delimiter as pipe. Is that correct?
If that is correct, what do you get when you run this?

| ldapsearch domain=ED search="(&(objectClass=eduPerson)(weillCornellEduCWID=paa2013))" attrs="weillCornellEduCWID,o" 
  | eval o1 =o | nomv o1

Also, give this a try

| ldapsearch domain=ED search="(&(objectClass=eduPerson)(weillCornellEduCWID=paa2013))" attrs="weillCornellEduCWID,o" 
| eventstats values(o) as o1 delim="|" | nomv o1
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...