[英]get a part of a binary file using gnu-coreutils, bash
I want to get a part of a binary file, from byte #480161397 to #480170447 (included, 9051 bytes in total) 我想获取二进制文件的一部分,从字节#480161397到#480170447(包括,总共9051字节)
I use cut -b
, and I expected the size of trunk1.gz to be 9051 bytes, but I get a different result. 我使用cut -b
,并且我期望trunk1.gz的大小为9051字节,但是得到了不同的结果。
$ wget https://commoncrawl.s3.amazonaws.com/crawl-data/CC-MAIN-2016-07/segments/1454701152097.59/warc/CC-MAIN-20160205193912-00264-ip-10-236-182-209.ec2.internal.warc.gz
$ cut -b480161397-480170447 CC-MAIN-20160205193912-00264-ip-10-236-182-209.ec2.internal.warc.gz >trunk1.gz
$ echo $((480170447-480161397+1))
9051
$ ls -l trunk1.gz
-rw-r--r-- 1 david staff 3400324 Sep 8 10:28 trunk1.gz
What is wrong? 怎么了?
cut -bN-M
copies the range NM
bytes from every line of the input. cut -bN-M
从输入的每一行复制范围NM
字节。
Example : 范例 :
$ cut -b4-7 <<END
0123456789
abcdefghij
ABCDEFGHIJ
END
Output : 输出 :
3456
defg
DEFG
Consider using dd
for your purposes. 考虑将dd
用于您的目的。
If you work with binary, I advise you to use dd
command. 如果使用二进制文件,建议您使用dd
命令。
dd if=trunk1.gz bs=1 skip=480161397 count=9051 of=output.bin
bs
is the block size and is set to 1 byte. bs
是块大小,设置为1个字节。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.