如何仅获取二进制文件的前十个字节 [英] How to get only the first ten bytes of a binary file

查看:233
本文介绍了如何仅获取二进制文件的前十个字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个bash脚本,该脚本需要获取文件的标头(前10个字节),然后在另一节中获取除前10个字节以外的所有内容.这些是二进制文件,在前10个字节中可能都有\0\n.似乎大多数实用程序都可使用ASCII文件.什么是完成此任务的好方法?

I am writing a bash script that needs to get the header (first 10 bytes) of a file and then in another section get everything except the first 10 bytes. These are binary files and will likely have \0's and \n's throughout the first 10 bytes. It seems like most utilities work with ASCII files. What is a good way to achieve this task?

推荐答案

要获取前10个字节(如前所述):

To get the first 10 bytes, as noted already:

head -c 10

要获取除前10个字节以外的所有字节(至少使用GNU tail):

To get all but the first 10 bytes (at least with GNU tail):

tail -c+11

这篇关于如何仅获取二进制文件的前十个字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆