二进制sed替换 [英] binary sed replacement
问题描述
我试图做一个二进制文件 SED
更换然而,我开始相信这是不可能的。从本质上讲就是我想要做的是类似以下内容:
SED -biS / \\(\\ XFF \\ xD8 [[:xdigit:]] \\ {1,\\} \\ XFF \\ xD9 \\)/ \\ 1 /文件。 JPG
我要实现的逻辑是:通过一个二进制文件,直到十六进制code FFD8
,请继续阅读直到 FFD9 扫描code>,只救什么是他们(在丢弃垃圾之前和之后,但包括
FFD8
和 FFD9
作为文件的保存部分)
有没有做到这一点的好办法?即使不使用 SED
?
编辑:我只是玩了一圈,发现这样做IMO最彻底的方法。我知道这grep的声明将采取行动贪婪。
hexdump都-ve1/1%.2x'dirty.jpg | grep的-o。FFD8 * ffd9| XXD -r -p> clean.jpg
BBE 是一个sed的二进制文件 ,并应努力更有效地比hexdumping /重建大型二进制文件。
I was attempting to do a sed
replacement in a binary file however I am beginning to believe that is not possible. Essentially what I wanted to do was similar to the following:
sed -bi "s/\(\xFF\xD8[[:xdigit:]]\{1,\}\xFF\xD9\)/\1/" file.jpg
The logic I wish to achieve is: scan through a binary file until the hex code FFD8
, continue reading until FFD9
, and only save what was between them (discards the junk before and after, but include FFD8
and FFD9
as the saved part of the file)
Is there a good way to do this? Even if not using sed
?
EDIT: I just was playing around and found the cleanest way to do it IMO. I am aware that this grep statement will act greedy.
hexdump -ve '1/1 "%.2x"' dirty.jpg | grep -o "ffd8.*ffd9" | xxd -r -p > clean.jpg
bbe is a "sed for binary files", and should work more efficiently for large binary files than hexdumping/reconstructing.
这篇关于二进制sed替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!