Search code examples
c++cbashbinaryoctal

how do I print a binary double array from commandline (unix)


I got binary file, that contains doubles. How do i print that out to a terminal. I've tried octaldump 'od' but cant figure out the syntax I've tried something like

head -c80 |od -f

But that doesnt work, the man page for od is extremely bad.

I've made a c program that does what I want, something like assuming 10double chunks.

double tmp[10];
while(fread(tmp,sizeof(double),10,stdin))
    for(int i=0;i<10;i++)  printf("%f\t",tmp[i]);

thanks.


Solution

  • Have you tried hexdump utility?

    hexdump -e ' [iterations]/[byte_count] "[format string]" ' filename
    

    Where format string should be "%f", byte count should be 8, and iterations the amount of floats you want to read