简体   繁体   中英

hex to bin file conversion in bash

This question has already been asked in many different forms. I need to convert a file that looks like this

41 20 42 20 43 20 44

to this

A B C D

This is just an example, but files WILL certainly contain non-printable characters. I wrote a simple piece of code in C that does this, but I'm curious can it be done with some of the basic tools that are available on most Linux distributions, such as dd or tr , or maybe some clever bash script?

For the sample input this works (in bash at least). Whether it will work for all input I'm not sure but I expect it probably will.

printf %b $(printf '\\x%s ' $(< infile)); echo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM