Fusionar líneas que no están en forma adecuada

Fusionar líneas que no están en forma adecuada

Tengo las líneas similares a las de abajo.

[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

Es necesario agregar la línea a la línea de salida de cmd original seguida de una coma. Y debería comenzar con un corchete que contenga números como se muestra a continuación

[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

Respuesta1

Si lo comprende bien, desea unir líneas que no comiencen con corchetes.

Aquí hay una forma de Perl:

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

Explicación:

\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

Reemplazo:

,           # a comma followed by a space

Resultado para el ejemplo dado:

[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

información relacionada