1

I use slapcat to do a full-text search in our very large ldap directory. As it is easier to match what I am looking for when I don't know where to look.

The problem is that it wraps long lines

slapcat -v | grep -A 1 "some search string"
somelongvar::linesoftesttext12345667890987654321234567887654321234567897654321
 wraps like this
nelaaro
  • 1,333
  • 3
  • 15
  • 20

3 Answers3

4

A bit late maybe, but man slapcat shows:

OPTIONS
       -o option[=value]
              Specify an option with a(n optional) value.  Possible generic options/values are:

                     syslog=<subsystems>  (see `-s' in slapd(8))
                     syslog-level=<level> (see `-S' in slapd(8))
                     syslog-user=<user>   (see `-l' in slapd(8))

                     ldif-wrap={no|<n>}

              n is the number of columns allowed for the LDIF output
              (n equal to 0 uses the default, corresponding to 78).
              The minimum is 2, leaving space for one character and one
              continuation character.
              Use no for no wrap.

So slapcat -o ldif-wrap=no ... does what you want.

1

I found a solution to this from this answer https://stackoverflow.com/a/10002241/619760

This matches line ending \n followed by a and joins the lines.

slapcat -v | grep -A 1 "some search string" | sed '$!N;s/\n //;P;D'
somelongvar::linesoftesttext12345667890987654321234567887654321234567897654321wraps like this
nelaaro
  • 1,333
  • 3
  • 15
  • 20
0

Using Raku (formerly known as Perl_6)

~$ raku -ne 'if .chars > 78 {put $_ ~ ($_ with get) } else { put $_ };'  file

We can recreate this problem for any such file, not just slapcat output. Below we generate an alphabetic "truncated triangle" file, tri_N-to-Z.txt :

~$ raku -e 'for (0..12) -> $i { $_.[0..(25-$i)].join.put given "\x0061".."\x07A"};'  > tri_N-to-Z.txt

Here we break lines at 20 characters (wraps 7 lines)...

Sample Input:

~$ cat tri_N-to-Z.txt | raku -pe 's/^ (.**20) /{"$0\n"}/;' > tri_N-to-Z_wrapped.txt
~$ cat tri_N-to-Z_wrapped.txt
abcdefghijklmnopqrst
uvwxyz
abcdefghijklmnopqrst
uvwxy
abcdefghijklmnopqrst
uvwx
abcdefghijklmnopqrst
uvw
abcdefghijklmnopqrst
uv
abcdefghijklmnopqrst
u
abcdefghijklmnopqrst

abcdefghijklmnopqrs
abcdefghijklmnopqr
abcdefghijklmnopq
abcdefghijklmnop
abcdefghijklmno
abcdefghijklmn

Sample Output (recreates the original truncated triangle):

~$ raku -ne 'if .chars > 19 {put $_ ~ ($_ with get) } else { put $_ };' tri_N-to-Z_wrapped.txt
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxy
abcdefghijklmnopqrstuvwx
abcdefghijklmnopqrstuvw
abcdefghijklmnopqrstuv
abcdefghijklmnopqrstu
abcdefghijklmnopqrst
abcdefghijklmnopqrs
abcdefghijklmnopqr
abcdefghijklmnopq
abcdefghijklmnop
abcdefghijklmno
abcdefghijklmn

Note: the code ($_ with get) is simply to make sure that get is called on an existent line, e.g. at the very end of the file (with checks for definedness).

https://raku.org

jubilatious1
  • 2,385
  • 8
  • 16