linux - Bash script that prints out contents of a binary file, one word at a time, without xxd -
i'd create bash script reads binary file, word (32-bits) word , pass word application called devmem.
right now, have:
... (( i=0; i<${num_words}; i++ )) val=$(dd if=${file_name} skip=${i} count=1 bs=4 2>/dev/null) echo -e "${val}" # weird output... devmem ${some_address} 32 ${val} done ...
${val} has weird (ascii?) format character representations looks diamond question mark.
if replace "val=" line with:
val=$(dd ... | xxd -r -p)
i desired output.
what easiest way of replicating functionality of xxd using bash?
note: i'm working on embedded linux project requirements don't allow me install xxd.
this script performance driven, please correct me if i'm wrong in approach, reason chose (dd -> binary word -> devmem) instead of (hexdump -> file, parse file -> devmem). - regardless of optimal route end goal, exercise has been giving me trouble , i'd appreciate helping me figure out how this.
thanks!
as see shouldn't use '|' or echo, because both ascii tools. instead think '>' work you.
think devmem
bash function or alias, try this:
for (( i=0; i<${num_words}; i++ )) dd if=${file_name} skip=${i} count=1 bs=4 2>/dev/null 1> binary_file # echo -e "${val}" # weird output... devmem ${some_address} 32 $(cat binary_file) done
"as cat catenates streams of bytes, can used concatenate binary files, concatenate sequence of bytes." wiki
or can alter devmem
accept file input...i hope help!
Comments
Post a Comment