linux将文件切分不等数量的,如何使用Python将单个文件拆分为多个不同大小的文件...

作者尝试使用Python脚本配合shell脚本,在不同操作系统上按指定偏移量拆分大型文件。但在ESX 6.5环境下遇到head命令不兼容的问题,寻求能在该环境下正常工作的替代方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我编写了一个python脚本,从列表中读取文件偏移量和文件名,并将一个大文件分成多个文件。对于拆分,我使用shell脚本,它将这些名称和偏移量作为输入,并使用head命令创建多个输出文件。我使用python将输入发送到shell脚本。这在我的Windows7和其他Linux系统中运行良好。但是,当我试图在esx6.5hypervisor上使用相同的脚本时,我意识到我不能在esx6.5中使用相同的shell脚本,因为head command不能像在其他操作系统中那样工作。在

list=['IdleChk_1_E1.txt','749','IdleChk_2_E1.txt','749','reg_fifo_E1.txt','5922','igu_fifo_E1.txt','161','protection_override_E1.txt','1904','fw_asserts_E1.txt','708','McpTrace.txt文件'15578','物理_转储.txt','129','GrcDumpE1.bin','3629656']

偶数元素是文件名,奇数元素是大小。在

下面是我用来向shell脚本发送输入的命令:Process_three=subprocess.Popen("./read.sh %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s" \

%(''.join(map(str, list_info[1:2])), ''.join(map(str, list_info[0:1])),\

''.join(map(str, list_info[3:4])), ''.join(map(str, list_info[2:3])),\

''.join(map(str, list_info[5:6])), ''.join(map(str, list_info[4:5])),\

''.join(map(str, list_info[7:8])), ''.join(map(str, list_info[6:7])),\

''.join(map(str, list_info[9:10])), ''.join(map(str, list_info[8:9])),\

''.join(map(str, list_info[11:12])), ''.join(map(str, list_info[10:11])),\

''.join(map(str, list_info[13:14])), ''.join(map(str, list_info[12:13])),\

''.join(map(str, list_info[15:16])), ''.join(map(str, list_info[14:15])),\

''.join(map(str, list_info[17:18])), ''.join(map(str, list_info[16:17])),\

file_name), stdout=subprocess.PIPE, shell=True)

(temp, error) = Process_three.communicate()

这是我的shell脚本。在

^{pr2}$

在ESX中,只有第一个头命令输出有效。在

有没有其他方法分割文件。我知道有split命令,但是这个命令将文件分成两半。我需要动态大小的文件。

我希望我能从python中分离出来。顺便说一下,我是Python新手。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值