合并不符合要求的行

合并不符合要求的行

我有类似下面的内容。

[1] 07:37:38 [bb..], qw, Exited with errojjjvice not known
[2] 07:37:39 [bfb.], fg, , This is FILE1, Stderrle or directory
[3] 07:37:39 [SU..], b b, ,, Stderr: bash: /sauch file or directory
cat: /root/file1: No, such, file or directory
[4] 07:37:39 [SUCCESS], gh, , This is F :, No, such file or directory
[5] 07:37:39 [SUCCESS], jk, ,, Stderr: bash: , No, such file or directory
nnnnnn, oot/file1: No, such, file or directory
hylll;; ooppgggh
[6] 07:37:39 [SUCCESS], jjj, ,, Stderr: bash:  No, such file or directory
cat: /root/file1: No, such, file or directory

需要将该行附加到其原始 cmd 输出行,后跟逗号。并且应以包含数字的方括号开头,如下所示

[1] 07:37:38 [bb..], qw, Exited with errojjjvice not known
[2] 07:37:39 [bfb.], fg, , This is FILE1, Stderrle or directory
[3] 07:37:39 [SU..], b b, ,, Stderr: bash: /sauch file or directory, cat: /root/file1: No, such, file or directory
[4] 07:37:39 [SUCCESS], gh, , This is F :, No, such file or directory
[5] 07:37:39 [SUCCESS], jk, ,, Stderr: bash: , No, such file or directory, nnnnnn, oot/file1: No, such, file or directory, hylll;; ooppgggh
[6] 07:37:39 [SUCCESS], jjj, ,, Stderr: bash:  No, such file or directory, cat: /root/file1: No, such, file or directory

答案1

如果理解得好,您想要连接不以方括号开头的行。

这是一个 perl 方法:

perl -0777 -i -ape 's/\R(?=[^[])/, /g' file

解释:

\R          # any kind of linebreak (i.e. \r, \n, \r\n)
(?=         # positive lookahead, zero-length assertion that make sure we have after:
    [^[]    # any character that is not an opening square bracket
)           # end lookahead

替代品:

,           # a comma followed by a space

给定示例的结果:

[1] 07:37:38 [bb..], qw, Exited with errojjjvice not known
[2] 07:37:39 [bfb.], fg, , This is FILE1, Stderrle or directory
[3] 07:37:39 [SU..], b b, ,, Stderr: bash: /sauch file or directory, cat: /root/file1: No, such, file or directory
[4] 07:37:39 [SUCCESS], gh, , This is F :, No, such file or directory
[5] 07:37:39 [SUCCESS], jk, ,, Stderr: bash: , No, such file or directory, nnnnnn, oot/file1: No, such, file or directory, hylll;; ooppgggh
[6] 07:37:39 [SUCCESS], jjj, ,, Stderr: bash:  No, such file or directory, cat: /root/file1: No, such, file or directory

相关内容