gpt4 book ai didi

Bash 脚本 - 读取二进制文件

转载 作者:行者123 更新时间:2023-11-29 08:59:29 24 4
gpt4 key购买 nike

我是脚本编写的新手,但我有很多使用 C# 和 Java 等语言进行编程的经验。

我有a file that contains binary data .我想编写一个 Bash 脚本来读取该文件中包含的年、月和日,这样我就可以根据记录的日期将相关的 MOD 文件分类到文件夹中。我无法找到一种方法来读取二进制数据并在 bash 脚本中对其进行解析。有什么办法吗?

最佳答案

您可以为此使用 od(加上 head 和 awk 进行一些后处理)。获取年份:

year=$(od -t x2 --skip-bytes=6 --read-bytes=2 file.moi | head -1 | awk '{print $2}')

当月:

month=$(od -t x1 --skip-bytes=8 --read-bytes=1 file.moi | head -1 | awk '{print $2}')

那一天:

day=$(od -t x1 --skip-bytes=9 --read-bytes=1 file.moi | head -1 | awk '{print $2}')

关于Bash 脚本 - 读取二进制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1972222/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com