使用Bash或Python脚本复制和重命名文件

时间:2017-10-19 13:04:32

标签: python bash

目前我有一个名为0x4f0DAA112142FFC4BA1B9f3B76bcd238A094D65B的文件,如下所示:

6060604052361561006c5760e060020a60003504630121b93f81146100e15780636637b882146101615780636dbf2fa0146101935780638da5cb5b1461026a578063a6f9dae11461027c578063beabacc8146102ae578063d979f5aa14610322578063e1fa763814610354575b61050b600060006000600460005054111561051d576004805460001901905560015460035460055460e260020a6320998771026060908152606492909252600160a060020a03908116608452909116906382661dc49060a49060209060448187876161da5a03f11561000257506105c3915050565b6105cb60043560005433600160a060020a039081169116141561015e57600180547fc9d27afe0000000000000000000000000000000000000000000000000000000060609081526064849052608492909252600160a060020a03169063c9d27afe9060a4906020906044816000876161da5a03f115610002575050505b50565b6105cb60043560005433600160a060020a039081169116141561015e5760018054600160a060020a0319168217905550565b60806020604435600481810135601f8101849004909302840160405260608381526105cb9482359460248035956064949391019190819083828082843750949650505050505050600054600160a060020a039081163390911614156102655782600160a060020a03168282604051808280519060200190808383829060006004602084601f0104600f02600301f150905090810190601f16801561024b5780820380516001836020036101000a031916815260200191505b5091505060006040518083038185876185025a03f1505050505b505050565b6105cd600054600160a060020a031681565b6105cb60043560005433600160a060020a039081169116141561015e5760008054600160a060020a0319168217905550565b6105cb6004356024356044356000805433600160a060020a039081169116141561031c5760e060020a63a9059cbb026060908152600160a060020a03848116606452608484905285929083169163a9059cbb9160a4916020916044908290876161da5a03f115610002575050505b50505050565b6105cb60043560005433600160a060020a039081169116141561015e5760028054600160a060020a0319168217905550565b6105cb60043560243560005433600160a060020a03908116911614156105075760015460e060020a6370a0823102606090815230600160a060020a0390811660645291909116906370a08231906084906020906024816000876161da5a03f1156100025750506040805180516006556002546001547f1a695230000000000000000000000000000000000000000000000000000000008352600160a060020a039081166004840152925192169250631a695230916024828101926000929190829003018183876161da5a03f1156100025750505060048181556003839055600154604080517f013cf08b00000000000000000000000000000000000000000000000000000000815292830185905251600160a060020a03919091169163013cf08b91602482810192602092919082900301816000876161da5a03f11561000257505060408051805160058054600160a060020a0319169091179081905560015460035460e260020a63209987710284526004840152600160a060020a0391821660248401529251921692506382661dc491604482810192602092919082900301816000876161da5a03f115610002575050505b5050565b60408051918252519081900360200190f35b60015460e060020a6370a0823102606090815230600160a060020a0390811660645291909116906370a082319060849060209060248187876161da5a03f11561000257505060408051805160015460025460e060020a63a9059cbb028452600160a060020a039081166004850152602484018390529351919550909216925063a9059cbb916044828101926020929190829003018188876161da5a03f115610002575050505b600191505090565b005b6060908152602090f3

我想要做的是,将其复制1,000次,并且每次都给它起名称以表明我复制了多少次,例如 - 我希望有文件:

0x4f0DAA112142FFC4BA1B9f3B76bcd238A094D65B_000
0x4f0DAA112142FFC4BA1B9f3B76bcd238A094D65B_001
...
0x4f0DAA112142FFC4BA1B9f3B76bcd238A094D65B_999

我的第一直觉是用Python做到这一点,但我想它也可以在Bash中轻松快速地完成,但事情是我不知道如何。

3 个答案:

答案 0 :(得分:2)

将范围扩展更改为omdbtool -t "Ice Age: The Meltdown" | wget `sed -n '/^poster/{n;p;}'` 似乎有效。

{000..999}

答案 1 :(得分:1)

使用Python:

import shutil

filename = '0x4f0DAA112142FFC4BA1B9f3B76bcd238A094D65B'
for i in range(1, 1000):
    shutil.copyfile(filename, filename + '%03d' % i)

答案 2 :(得分:-1)

使用bash和awk可以得到:

for i in {0..999}
do 
  cp 0x4f0DAA112142FFC4BA1B9f3B76bcd238A094D65B `echo "$i 0x4f0DAA112142FFC4BA1B9f3B76bcd238A094D65B" | awk '{printf("%s_%03d\n",$2,$1)}'`
done