如何使用unix从文件中提取特定字节

发布于 2024-08-16 21:30:47 字数 279 浏览 2 评论 0原文

如何从二进制文件中的某些位置提取 12 字节块。

如果我想提取前 12 个字节,我可以做类似的事情

head -c12 file.bin>output

如果我想从 byte61 中提取 12 个字节,我可以做类似的事情

head -c72 file.bin|tail -c12 >output

如果我有 20 个 12 字节块我需要提取,有没有更简单的方法,

谢谢

how do I extract 12byte chunks from a binary file at certain positions within the file.

If I wanted to extract the first 12 bytes I could do something like

head -c12 file.bin>output

If I wanted to extract 12 bytes from byte61 I could do something like

head -c72 file.bin|tail -c12 >output

Is there a simpler way if I have something like 20 12byte chunks I need to extract

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

↙温凉少女 2024-08-23 21:30:47

使用dd

dd bs=1 seek=60 count=12 if=file.bin of=output

您可以编写一个shell循环来替换数字。

如果有很多工作要做或者需要非常快,您还可以考虑使用 awk、Perl 或 Python。

Use dd:

dd bs=1 seek=60 count=12 if=file.bin of=output

You can write a shell loop to substitute the numbers.

You could also consider using awk, Perl or Python, if there's a lot of them to do or it needs to be really fast.

如日中天 2024-08-23 21:30:47

使用 xxd:

xxd -p -seek 3d -l 12 file.bin > output

3d 表示十六进制的 61

使用 hexdump:

hexdump -ve '16/1 "%0.2x " "\n"' -s 3d -n 12 file.bin > output

Using xxd:

xxd -p -seek 3d -l 12 file.bin > output

3d means 61 in hexadecimal

Using hexdump:

hexdump -ve '16/1 "%0.2x " "\n"' -s 3d -n 12 file.bin > output
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文