| Hufnus 2006-10-26, 1:30 am |
| I am testing a bash script that counts the number of
times a binary patten occurrs in a file. I can not rely
on the presence of text lines when scanning for the pattern.
the pattern is a string of hex bytes, lets say 5 spaces like:
'2020202020' (using od format).
now this will find if the patten exists on the file, but I think
I need to precut the file where the patten was founf, then
repeat and so on untill I have the count. How would I find
offset to start next scan?
I am now using something like:
$1 is file path
$2 is the sample hex string: 2020202020
NOTE: This is not a fair choice, because of the problem with
parsing how many 5spaces are in a long string of spaces in a
file. So for simplicity, lets assume that the string WILL
BE UNIQUE, but there will be N instances in a binary
file. I am just trying to determine N, the where is nice but
can live w/o.
count=${#2}
echo -n $( cat $1 | od -w$count -t x1z ) | sed 's/ //g' | grep
"$2" | wc -l 2> /dev/null
The above just reports the 1st match!
I know Stephanie, Chris or another of you might have hold on
this.
Thanks
TonyB
Fall is my favorite season in Los Angeles, watching the birds
change color and fall from the trees.
David Letterman (1947 - )
--
__ __ _ I N C. http://www.sysdev.org
/ __|\\// __|| \ __ __ / tonyb@sysdev.org
\__ \ \/\__ \||)|/ O_)\/ / \/ System Tools / Utilities
|___/ || ___/|_ /\___|\_/ WIntel / Linux Device Drivers
|