如何为"xxd -r"输入有效的信息?在vim中删除字节时? [英] How to make a valid input for "xxd -r" in vim when removing a byte?

查看:207
本文介绍了如何为"xxd -r"输入有效的信息?在vim中删除字节时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建一个名为test的文件,其中包含以下内容:

Create a file named as test containing the following content:

0123456789abcdef0123456789abcdef

我想使用xxd删除第一个0.用vim -b test打开它,然后在vim中运行:%!xxd.结果是:

I want to remove the first 0 with the use of xxd. Open it with vim -b test then run :%!xxd inside vim. The result is:

0000000: 3031 3233 3435 3637 3839 6162 6364 6566  0123456789abcdef
0000010: 3031 3233 3435 3637 3839 6162 6364 6566  0123456789abcdef
0000020: 0a                                       .      

然后我删除第一个0的十六进制代码30:

Then I remove the hex code 30 for the first 0:

0000000: 31 3233 3435 3637 3839 6162 6364 6566  0123456789abcdef
0000010: 3031 3233 3435 3637 3839 6162 6364 6566  0123456789abcdef
0000020: 0a                                       .

然后我运行:%!xxd -r读回十六进制.结果是:

Then I run :%!xxd -r to read the hex back. The result is:

^@23456789abcdef^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@

结果出现乱码.我知道原因是上述内容不是有效的xxd输入.如果我删除行号和文本部分:

The result is garbled. I know that the reason is the above content is not a valid xxd input. If I remove the line numbers and the text part:

31 3233 3435 3637 3839 6162 6364 6566
3031 3233 3435 3637 3839 6162 6364 6566  
0a  

我运行:%!xxd -r -p读回十六进制.结果是正确的:

The I run :%!xxd -r -p to read the hex back. And the result is correct:

123456789abcdef0123456789abcdef

是否有更好的方法通过使用vim和xxd来完成这项工作?更好的方法意味着更少的编辑即可为xxd -r进行有效的输入.

Is there a better way to do this job with the use of vim and xxd? A better way means less editing to make a valid input for xxd -r.

推荐答案

您自己发现,删除字节偏移量列和文本列使您可以使用:%!xxd -r -p来获得所需的内容.那么,如何创建一个自定义命令来删除这些列,然后进行转换呢?无论如何,:%!xxd -r -p太多了.

You've discovered on your own that removing the byte offset column and text column allows you to use :%!xxd -r -p to get what you want. So how about creating a custom command to remove those columns and then do the conversion? :%!xxd -r -p is too much to type, anyway.

类似的东西:

:command MyXXDR %s#^[^:]*: \(\%(\x\+ \)\+\) .*#\1# | %!xxd -r -p

如果您在编辑时过多地弄乱了文件格式(例如,替代命令与删除所需的文本不匹配),则此精确命令可能会导致问题,但是您明白了.

This exact command may cause problems if you have messed up the format of the file too much with your edits (i.e. if the substitute command doesn't match to remove the necessary text), but you get the idea.

这篇关于如何为"xxd -r"输入有效的信息?在vim中删除字节时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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