如何使用Linux命令将文本文件转换为二进制文件 [英] How to convert a text file to binary file using linux commands

查看:2046
本文介绍了如何使用Linux命令将文本文件转换为二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本(字符串)格式的二进制十六进制代码.如何使用cat和echo之类的linux命令将其转换为二进制文件?

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 ?

我知道命令后面的命令会创建一个二进制test.bin.但是,如果此十六进制代码在另一个.txt文件中怎么办?如何将文本文件的内容捕捉"到"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

推荐答案

使用xxd -r.它将十六进制转储恢复为其二进制表示形式.

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

编辑:-p参数也非常有用.它接受普通"十六进制值,但忽略空格和行更改.

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

这篇关于如何使用Linux命令将文本文件转换为二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆