我使用 slapcat 在我们非常大的 ldap 目录中进行全文搜索。因为当我不知道在哪里寻找时,更容易匹配我正在寻找的东西。
问题是它换行很长
slapcat -v | grep -A 1 "some search string"
somelongvar::linesoftesttext12345667890987654321234567887654321234567897654321
wraps like this
答案1
也许有点晚了,但man slapcat
显示:
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.
slapcat -o ldif-wrap=no ...
你想要的也是如此。
答案2
我从这个答案中找到了解决方案https://stackoverflow.com/a/10002241/619760
这匹配行结尾\n
后跟 a并连接行。
slapcat -v | grep -A 1 "some search string" | sed '$!N;s/\n //;P;D'
somelongvar::linesoftesttext12345667890987654321234567887654321234567897654321wraps like this
答案3
使用乐(以前称为 Perl_6)
~$ raku -ne 'if .chars > 78 {put $_ ~ ($_ with get) } else { put $_ };' file
我们可以为任何此类文件重现此问题,而不仅仅是slapcat
输出。下面我们生成一个字母“截断三角形”文件tri_N-to-Z.txt
:
~$ raku -e 'for (0..12) -> $i { $_.[0..(25-$i)].join.put given "\x0061".."\x07A"};' > tri_N-to-Z.txt
这里我们在 20 个字符处换行(换行 7 行)...
输入示例:
~$ 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
示例输出(重新创建原始截断三角形):
~$ 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
注意:代码($_ with get)
只是为了确保get
在现有行上调用它,例如在文件的最后(with
检查定义)。