다양한 복사 및 붙여넣기를 사용하여 테이블 형식을 다시 지정하세요.

다양한 복사 및 붙여넣기를 사용하여 테이블 형식을 다시 지정하세요.

내 파일에는 다음이 있습니다.

00550 Peptidoglycan biosynthesis (2)
K01000
K02563
00511 Other glycan degradation (6)
K01190
K01191
K01192
K01201
K01227
K12309  

다음과 같은 것이 필요합니다.

K01000,00550,Peptidoglycan biosynthesis (2)
K02563,00550,Peptidoglycan biosynthesis (2)
K01190,00511, Other glycan degradation (6)
K01191,00511, Other glycan degradation (6)
K01192,00511, Other glycan degradation (6)
K01201,00511, Other glycan degradation (6)
K01227,00511, Other glycan degradation (6)
K12309,00511, Other glycan degradation (6)  

Linux에서 이 작업을 어떻게 수행할 수 있나요?

답변1

노력하다

awk -vOFS=, '/^[0-9]* / {$1 = $1; GL = $0; next} {print $0, GL}' file

답변2

sed '/(/{s/ /,/;h;d;};G;s/\n/,/' filename

표현식 sed, 한 번에 하나의 명령:

/(/{
#use "(" to spot a new name
    s/ /,/  #replace first space (after the number) with ,
    h       #save it in the hold space
    d       #delete (don't output) and start next cycle (read next line)
}
#only reached when no "(" found
G           #append saved text from hold to current line
s/\n/,/     #replace the linebreak with a ,

관련 정보