6

我的 ldif 文件中有一些条目使我的转储不利于下次导入。

sambaPasswordHistory: 712BC301C488FD2651BEF5AA11899950547B9ED3C059FF83CE39049B
 BAEECB31692629A94A3C1F4737E3EA854C001704793DB9A67EB977563CE601DF98E7E23C2851F
 082D3D695C8655378629DCCDAF125ACA63141B361190ABC750AF403FDEF000000000000000000
 00000000000000000000000000000000000000000000000000000000000000000000000000000
 00000000000000000000000000000000000000000000000000000000000000000000000000000
 00000000000000000000000000000000000000000000000000000000000000000000000000000
 00000000000000000000000000000000000000000000000000000000000000000000000000000
 00000000000000000000000000000000000000000000000000000000000000000000000000000
 00000000000000000000000000000000000000000000000000000000000000000000000000000
 00000000000000000000000000000000000000000000000000000000000000000000000000000
 00000000000000000000000000000000000000000000000000000000000000000000000000000
 00000000000000000000000000000000000000000000000000000000000000000000000000000
 000000000000000000000000000000000000000000000000000000000
homeDirectory: /home_nfs/

如何使用 sed/awk/etc 将其更改为

sambaPasswordHistory: 712BC301C488FD2651BEF5AA11899950547B9ED3C059FF83CE39049BBAEECB31692629A94A3C1F4737E3EA854C001704793DB9A67EB977563CE601DF98E7E23C2851F082D3D695C8655378629DCCDAF125ACA63141B361190ABC750AF403FDEF000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
homeDirectory: /home_nfs/

又名将所有内容放在一行中

4

6 回答 6

10

一种使用方式GNU sed

sed -n 'H; ${ x; s/\n//; s/\n //g; p}' file.txt

结果:

sambaPasswordHistory: 712BC301C488FD2651BEF5AA11899950547B9ED3C059FF83CE39049BBAEECB31692629A94A3C1F4737E3EA854C001704793DB9A67EB977563CE601DF98E7E23C2851F082D3D695C8655378629DCCDAF125ACA63141B361190ABC750AF403FDEF000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
homeDirectory: /home_nfs/
于 2012-10-30T13:02:28.240 回答
2
$ cat file
sambaPasswordHistory: abc
 def
 12345
 67
homeDirectory: /home_nfs/
$
$ awk 'NR>1 && !sub(/^ /,""){print s; s=""} {s = s $0} END{print s}' file
sambaPasswordHistory: abcdef1234567
homeDirectory: /home_nfs/
于 2012-10-30T13:01:00.050 回答
1

这可能对您有用(GNU sed):

sed ':a;N;s/\n //;ta;P;D' file

打开两行窗口。删除一个换行符后跟一个空格并重复该模式失败。最后打印第一行,如果模式空间中还有第二行,重复。

于 2012-10-30T14:58:17.123 回答
0

使用 sed 的一种方法:

sed ':a;$!N;s/\n //;ta'  file

sed 加入(N)除最后一行($!)之外的每一行。加入后,将删除后跟空格(\n)的换行符。'ta' 是循环到分支 'a' 直到替换失败。

于 2012-10-30T12:52:06.623 回答
0

如果 的唯一出现\n,即换行符后跟空格,是需要加入行的地方,你可以这样使用bbe

<file bbe -e 's/\n //'
于 2012-10-30T13:29:15.047 回答
0

另一种解决方案:

awk 'ORS="";!/home/{$1=$1; print}{RS="\n"}END{print "\n" $0 "\n"}' file
于 2012-10-31T15:47:16.980 回答