I am using the grep
command on a binary file (-a
flag included) and want the output of the --binary-offset
or -b
flag without actually printing the match, since the binary data is useless to me and causes the terminal to behave strangely (my guess is that the terminal is interpreting some of the binary as terminal commands).
Currently, I'm using the command:
dd ... 2>/dev/null | grep -abFf - file_to_search
to grep for a binary string (result of dd
) in file_to_search
The output looks like:
offset:[large string of binary characters]
How can I print just the offsets (without the large string of binary characters)?
It is not very clear what is inside of the "large string of binary characters" but ading an extra "grep -o Number in the beginning of the line" might do what you want:
dd ... 2>/dev/null | grep -abFf - file_to_search | grep -oP '^\d+:'
If you want just the first offset:
...| grep -oP -m 1 '^\d+:'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With