将头部集成到单行bashCLI中

我有这个命令

$ sha1sum file.bin | cut -f1 -d " "

计算某些 eeprom 内容的 sha1sum。管道后面跟着 cut 是为了去掉输出中的文件位置,只检索 sha1。

我的问题是我需要Nfile.bin. 该文件是一个 32 字节(固定长度)行的表/数组。

我知道我必须输入一些head -n N,但不知道如何进行重定向。语法是head -n N <file>.

我天真地尝试过,sha1sum file.bin | cut -f1 -d " " | head -n 8但没有用。我需要 shell 以某种方式理解这一点:sha1sum(head -n 8 file.bin) | cut -f1 -d " ",但我猜我们不能在 shell 中使用数学函数语法......

请问怎么做?问候

回答

使 的head输入的输出sha1sum,就像 的输出sha1sum是 的输入一样cut

head -n 8 file.bin | sha1sum | cut -d " " -f1

或者,如果文件是二进制文件,则使用前 N 个字节 -c

head -c 1024 file.bin | sha1sum | cut -d " " -f1


以上是将头部集成到单行bashCLI中的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>