Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm looking for a linux command to copy every other byte from a binary file. Another way to state this: I want to copy only the odd numbered bytes or only the even numbered bytes from a file.
I am familiar with other programs such as head and tail that let me trim the beginning or end of a file, but they don't seem like they will help me in this case.
I'm hoping some sort of built-in utility exists so I don't have to write my own C program to do this.
Why do you want to do this? Knowing the whole picture might help us give better answers.
I want to believe that "dd" will do this, but I don't have time to dig into it.
I'm dealing with a signal acquisition card that outputs interlaced data to file. I need to de-interlace the files in order to view the data properly. It happens in this case that the de-interlace process simply involves copying the odd bytes into one file and the even bytes into another file.
I looked at the dd man page and didn't see an applicable option.
This will print the odd bytes in hexadecimal as ASCII.
Change $2 to $3 for the even bytes.
If you want decimal representations, change the print format in the awk action.
This will print the odd bytes in hexadecimal as ASCII.
Change $2 to $3 for the even bytes.
If you want decimal representations, change the print format in the awk action.
What if I need the data back in binary format? How do I convert the ASCII text output back into binary?
dd is doing only block wise copys of data - and it can only skip leading block in input and/or output files.
the block sizes control how big the chunk of data for each read/write operation is. that is helpful for speeding things up. it might also have some impact when operating with char devices and streams. the above mentioned command line specification of "c 2" and similar seemingly is faulty and thus will be rejected by the tool
rationale: dd wont work for you.
od is a tool for printing binary data in a human readable fashion, thus using ASCII decoded formats as output in a line based fashion. to my best understanding it can not extract binary data following some pattern to some other binary data file.
rationale: od wont work for you.
Write a C program to do this. You are doing signal analysis, a pretty technical thing and you have a highly specific channel separation requirement of a binary file.
What happens if/when you go to 4, 6, or 8 channels?
use open(), read() and process every byte in that file
Use argc and argv to allow for input/output names.
Write it so that you can extend it for the next time when the customized requirements change.
Very simple example, untested, but compiles in gcc:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.