我有大量的bz2
格式的文件(30GB
)没有任何头。我可以用下面的pileline
轻松地将它们分成500M
个大小
bzcat logging.abc_gps.bz2 | pv | split -b 500M -d -a 4 --filter='bzip > $FILE.csv.bz2' - splitted_file-
但是我无法添加要包含每个分割的bz2
文件的头文件['a' 'b' 'c' 'd' 'e' 'f' 'timestamp']
更重要的是,我不希望基于500M
分割文件,而是希望基于数据中timestamp
的内容每天分割bz2
文件(例如:splitted_file_2021-01-01.csv.bz2
和splitted_file_2021-01-02.csv.bz2
)
数据是以制表符分隔的文本,如下所示(无标题,需要添加):
19252547212 1 3041 2 1 74.18 1.8504 2021-05-01 00:00:00
19252547213 1 5055 2 1 0 0 2021-05-01 00:00:00
19252547214 1 5073 1 1 53.81 0.1836 2021-05-01 00:00:00
您可以使用
bz2
包打开BZ2编码的文件,并将其视为常规文件对象。二进制读/写有一个较小的性能优势。假设您的数据是ASCII或UTF-8,并且数据中不需要转义制表符,您可以逐行读取文件,在出现新的时间戳时打开并写入输出你可以通过管道来加速这一过程。为将在不同内核上并行运行的单独bzip2进程提供解密和加密。您可以在脚本本身中创建管道和文件,而不是shell管道。假设系统上存在
bzip2
,则可以执行以下操作。我添加了tqdm
模块来打印进程相关问题 更多 >
编程相关推荐