Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a text file to binary file using linux commands

I have hex code of a binary in text (string) format. How do I convert it to a binary file using linux commands like cat and echo ?

I know command following command with create a binary test.bin. But what if this hexcode is in another .txt file ? How do I "cat" the content of text file to "echo" and generate a binary file ?

# echo -e "\x00\x001" > test.bin

like image 575
aMa Avatar asked Jan 30 '15 18:01

aMa


People also ask

How do you convert a file to binary in Linux?

use xxd -r . it reverts a hexdump to its binary representation. Edit: The -p parameter is also very useful. It accepts "plain" hexadecimal values, but ignores whitespace and line changes.

How do I convert a BIN file to a text file in Linux?

Code: awk '{for(i=2; i<=NF; i++) printf "%c", 0+sprintf ("%d", "0x"$i)}' file Col1 Col2 Col3 Col4 ABC 00000001 15-Dec-15 13000 ABC 00000001 31-Jan-16 13500 . . . A few chars are recognizable ("\", "A", "B", etc), but the main part is garbage.

How do I open a text file in binary?

To open the Binary Editor on an existing file, go to menu File > Open > File, select the file you want to edit, then select the drop arrow next to the Open button, and choose Open With > Binary Editor.


1 Answers

use xxd -r. it reverts a hexdump to its binary representation.

source and source

Edit: The -p parameter is also very useful. It accepts "plain" hexadecimal values, but ignores whitespace and line changes.

So, if you have a plain text dump like this:

echo "0000 4865 6c6c 6f20 776f 726c 6421 0000" > text_dump

You can convert it to binary with:

xxd -r -p text_dump > binary_dump

And then get useful output with something like:

xxd binary_dump
like image 79
1010 Avatar answered Oct 20 '22 01:10

1010