Re: OT: grep for hex characters

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2005-07-19 at 14:22 +0100, fergus wrote:
> Can anybody tell me how in general to grep files for hex characters 00
> to ff inclusive? I can do the 26 characters 01 to 1a (being ^A to ^Z
> respectively) and also 20 to 7e (being <space>, punct, 0-9, A-Z, more
> punct, a-z, more punct) but am stuck for everything else: 00, 1b to 1f
> and 7f to ff. Dunno, I thought it might be something like
> 
>         find . | xargs grep -l "\x8f"
> 
> but it's obviously not that. Thanks. (Maybe I can use sed just to find
> stuff, not replace it?)

Try "od" (octal dump) with the "-x" option, it will display a file as
hex, so you can grep for your characters.

Eg. 

od -x myfile | grep 6e

You can also use the option "-cx" to display both hex and ascii, so...

od -cx myfile | grep -C 3 6e

(grep -C 3 tells grep to show 3 lines of "context" around the match).

Cheers, Ben


Ben Stringer ===== ben@xxxxxxxxxxx
==================================



[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux