파일 이름당 한 줄이 있고 출력이 단일 공백으로 구분된 텍스트 파일을 줄 길이가 60자인 특정 블록으로 변환해야 합니다.
이와 같이:
>Directory1/file3 CTTSCCCTTTTTSEEEEECGGGSCEEEEECCCSSBCCCSCCCCCTTTCCCCCCCCSCBCCCCCCCCSCTTSCCCTTTTTSEEEEECGGGSCEEEEECCCSSBCCCSCCCCCTTTCCCCCCCCSCBCCCCCCCCSCTTSCCCTTTTTSEEEEECGGGSCEEEEECCCSSBCCCSCCCCCTTTCCCCCCCCSCBCCCCCCCCS
>Directory1/file4 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
...
...
~이 되다
>Directory1/file3
CTTSCCCTTTTTSEEEEECGGGSCEEEEECCCSSBCCCSCCCCCTTTCCCCCCCCSCBCC
CCCCCCSCTTSCCCTTTTTSEEEEECGGGSCEEEEECCCSSBCCCSCCCCCTTTCCCCCC
CCSCBCCCCCCCCSCTTSCCCTTTTTSEEEEECGGGSCEEEEECCCSSBCCCSCCCCCTT
TCCCCCCCCSCBCCCCCCCCS
>Directory1/file4
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAA
...
...
나는 무엇을 해야 합니까?
답변1
노력하다:
$ awk '{print $1; for (i=1;i<=length($2);i=i+60) print substr($2,i,60)}' file
>Directory1/file3
CTTSCCCTTTTTSEEEEECGGGSCEEEEECCCSSBCCCSCCCCCTTTCCCCCCCCSCBCC
CCCCCCSCTTSCCCTTTTTSEEEEECGGGSCEEEEECCCSSBCCCSCCCCCTTTCCCCCC
CCSCBCCCCCCCCSCTTSCCCTTTTTSEEEEECGGGSCEEEEECCCSSBCCCSCCCCCTT
TCCCCCCCCSCBCCCCCCCCS
>Directory1/file4
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAA
작동 방식:
print $1
그러면 줄의 첫 번째 필드가 인쇄됩니다.
for (i=1;i<=length($2);i=i+60) print substr($2,i,60)
줄의 두 번째 필드에서는 필드 끝에 도달할 때까지 한 번에 60자를 인쇄합니다.
답변2
GNU coreutils를 사용할 수 있습니다fold
:
fold -w60 file
답변3
이것도 좋아보이네요
sed -E "s/^(>[^\s]+) /\1\n/; s/([[:alnum:]]{60})/\1\n/g" /path/file
결과
$ sed -E "s/^>([^\s]+) /\1\n/; s/([[:alnum:]]{60})/\1\n/g" /path/file
>Directory1/file3
CTTSCCCTTTTTSEEEEECGGGSCEEEEECCCSSBCCCSCCCCCTTTCCCCCCCCSCBCC
CCCCCCSCTTSCCCTTTTTSEEEEECGGGSCEEEEECCCSSBCCCSCCCCCTTTCCCCCC
CCSCBCCCCCCCCSCTTSCCCTTTTTSEEEEECGGGSCEEEEECCCSSBCCCSCCCCCTT
TCCCCCCCCSCBCCCCCCCCS
>Directory1/file4
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAA
...
...
답변4
이것은 작동합니다:
fold -s -w 60
질문과 동일한 출력이 생성됩니다.
두 번째 부분에 공백이 없다고 가정하면 이것이 가장 쉬운 방법입니다.