我需要连接两个文件的块:
如果我需要连接整个文件,我可以简单地
cat file1 file2 > output但是我需要跳过第一个文件中的前1MB,而我只需要从第二个文件跳过10 MB。听起来像是dd的工作。
dd if=file1 bs=1M count=99 skip=1 of=temp1
dd if=file2 bs=1M count=10 of=temp2
cat temp1 temp2 > final_output有可能一步一步地做到这一点吗?不需要保存中间结果?我可以在dd中使用多个输入文件吗?
发布于 2016-05-02 11:36:39
dd也可以写到stdout。
( dd if=file1 bs=1M count=99 skip=1
dd if=file2 bs=1M count=10 ) > final_output发布于 2016-05-02 08:18:19
我不认为在一次dd调用中可以轻松地读取多个文件,但是可以在几个步骤中追加以构建输出文件:
dd if=file1 bs=1M count=99 skip=1 of=final_output
dd if=file2 bs=1M count=10 of=final_output oflag=append conv=notrunc您需要同时指定conv=notrunc和oflag=append。第一个避免截断输出,第二个从现有文件的末尾开始写入。
发布于 2016-05-02 15:39:49
使用bashism,以及在功能上“无用地使用cat",但与OP使用的语法最接近:
cat <(dd if=file1 bs=1M count=99 skip=1) \
<(dd if=file2 bs=1M count=10) \
> final_output(话虽如此,斯蒂芬·凯特的回答似乎是最有效的方法。)
https://unix.stackexchange.com/questions/280524
复制相似问题