아래와 비슷한 줄이 있습니다.
[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 -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