bashunixcommand-line-interfaceod

grep transformed content via od and show original file location


I am transforming some binary files and grepping a value in them:

od -t uL * | grep 0000

this is showing the matches that I am after but it's not showing the filename, and if I do use grep with the -H flag I only get 'standard input':

od -t uL * | grep -H 0000
(standard input):xxx 0000
(standard input):yyy 0000

How can I get the original filename returned?


Solution

  • That information is lost by the time grep is run, so you might have to loop over the files yourself

    for f in *; do
        od -t uL "$f" | awk -v f="$f" '/0000/ {print f":"$0}'
    done