我有一个文件,output.log,它有一个空格列表,‘',分隔整数范围为-2048,2048。我试图用xxd将其转换为二进制文件。我在用命令,
xxd -r -p output.log > output.bin但是,当我用xxd返回文件时,我会丢失所有的符号(-),并接收一些大于2048的值。有更好的方法吗?谢谢。
编辑:用样本数据..。
$ cat test
4 0 -3 -2 -1 200
$ xxd -r -p test > test.bin
$ xxd test.bin
0000000: 4012 00 @..也许我误解了xxd在做什么,在最后一个命令之后我期望看到的是看到我的原始输入数据被显示回来。这不对吗?
随着更大的数据集,我将看到正确的值不时显示,但仍然有吨的噪音在输出。
发布于 2016-06-05 00:28:16
您的输入源文件中可能有一些奇怪的字符,xxd可以很好地处理数字。尝试使用八进制转储od -c input查看您的数据,以查找任何奇怪的内容。
$ echo '-3000 -2048 -1 0 1 2048 3000' > foo.input
$ cat foo.input
-3000 -2048 -1 0 1 2048 3000
$ xxd foo.input > foo.hex
$ cat foo.hex
0000000: 2d33 3030 3020 2d32 3034 3820 2d31 2030 -3000 -2048 -1 0
0000010: 2031 2032 3034 3820 3330 3030 0a 1 2048 3000.
$ xxd -r foo.hex > foo.output
$ cat foo.output
-3000 -2048 -1 0 1 2048 3000https://stackoverflow.com/questions/37635440
复制相似问题