Binary grep on Linux?

后端 未结 6 1882
你的背包
你的背包 2020-12-13 18:53

Say I have generated the following binary file:

# generate file:
python -c \'import sys;[sys.stdout.write(chr(i)) for i in (0,0,0,0,2,4,6,8,0,1,3,0,5,20)]\'          


        
6条回答
  •  攒了一身酷
    2020-12-13 19:34

    One way to solve your immediate problem using only grep is to create a file containing a single null byte. After that, grep -abo -f null_byte_file target_file will produce the following output.

    0:
    1:
    2:
    3:
    8:
    11:
    

    That is of course each byte offset as requested by "-b" followed by a null byte as requested by "-o"

    I'd be the first to advocate perl, but in this case there's no need to bring in the extended family.

提交回复
热议问题