У меня есть строки, похожие на приведенные ниже.
[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