대용량 파일을 하위 파일로 분할합니다. 이 과정을 수행하는 방법은 무엇입니까? [복사]

대용량 파일을 하위 파일로 분할합니다. 이 과정을 수행하는 방법은 무엇입니까? [복사]

내 유닉스 상자에 2GB의 큰 파일이 있습니다. 이 파일에는 xml 줄이 포함되어 있습니다. 각 파일이 이제 대략 204MB라고 가정하고 이 파일을 10개 파일로 분할하려고 합니다. 따라서 10개 파일을 병합하면 원본 파일의 2GB가 반환되어야 합니다. 10개의 파일을 원본과 병합하면 콘텐츠가 재현 가능해야 합니다.

유닉스에서는 어떻게 해야 합니까?

답변1

다음 명령이 있습니다 split.

~$ split --help
Usage: split [OPTION]... [INPUT [PREFIX]]
Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...; default
size is 1000 lines, and default PREFIX is `x'.  With no INPUT, or when INPUT
is -, read standard input.
...
-n, --number=CHUNKS     generate CHUNKS output files.
...
CHUNKS may be:
N       split into N files based on size of input
K/N     output Kth of N to stdout
l/N     split into N files without splitting lines
l/K/N   output Kth of N to stdout without splitting lines
r/N     like `l' but use round robin distribution
r/K/N   likewise but only output Kth of N to stdout

그러니 당신은해야합니다

~$ split -n10 -d myfile mySubFile_

-d접미사를 사용하여 숫자 접미사(옵션)가 포함된 파일 10개를 생성합니다.mySubFile_

~$ ls -1t
mySubFile_00
mySubFile_01
mySubFile_02
mySubFile_03
mySubFile_04
mySubFile_05
mySubFile_06
mySubFile_07
mySubFile_08
mySubFile_09

넌 재편성할 수 있어

cat mySubFile_* > myfile

관련 정보