Nicht korrekt angeordnete Zeilen zusammenführen

Nicht korrekt angeordnete Zeilen zusammenführen

Bei mir sind die Zeilen ähnlich wie unten.

[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

Sie müssen die Zeile an die ursprüngliche Befehlsausgabezeile anhängen, gefolgt von einem Komma. Und sie sollte mit eckigen Klammern beginnen, die Zahlen enthalten, wie unten

[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

Antwort1

Wenn Sie es richtig verstehen, möchten Sie Zeilen verbinden, die nicht mit einer eckigen Klammer beginnen.

Hier ist eine Perl-Methode:

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

Erläuterung:

\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

Ersatz:

,           # a comma followed by a space

Ergebnis für gegebenes Beispiel:

[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

verwandte Informationen