【问题标题】:Hexdump -C but decimal instead of hexHexdump -C 但十进制而不是十六进制
【发布时间】:2014-11-01 19:10:40
【问题描述】:

centos 6.5 - 运行 hexdump

$ hexdump -C filecsv
00000000  44 4f 53 2c 20 50 61 74  69 65 6e 74 2c 20 41 63  |DOS, Patient, Ac|
00000010  63 74 20 23 2c 20 4d 52  20 23 2c 20 54 69 6d 65  |ct #, MR #, Time|

喜欢这种格式但希望将十六进制转换为十进制 我花了一些时间寻找但找不到这个?

【问题讨论】:

    标签: decimal ascii hexdump


    【解决方案1】:

    hexdump 支持通过-e 命令行选项指定格式字符串,看起来相当灵活。

    例子:

    $ hexdump -C b.c
    00000000  23 69 6e 63 6c 75 64 65  20 3c 73 74 64 69 6f 2e  |#include <stdio.|
    00000010  68 3e 0a 69 6e 74 20 6d  61 69 6e 28 29 7b 0a 20  |h>.int main(){. |
    00000020  20 70 72 69 6e 74 66 28  22 68 65 6c 6c 6f 20 77  | printf("hello w|
    00000030  6f 72 6c 64 5c 6e 22 29  3b 0a 20 20 72 65 74 75  |orld\n");.  retu|
    00000040  72 6e 20 30 3b 0a 7d 0a                           |rn 0;.}.|
    00000048
    $ hexdump -e'"%07.8_ax  " 8/1 "%02x " "  " 8/1 "%02x " "  |"' -e'16/1  "%_p"  "|\n"' b.c
    00000000  23 69 6e 63 6c 75 64 65  20 3c 73 74 64 69 6f 2e  |#include <stdio.|
    00000010  68 3e 0a 69 6e 74 20 6d  61 69 6e 28 29 7b 0a 20  |h>.int main(){. |
    00000020  20 70 72 69 6e 74 66 28  22 68 65 6c 6c 6f 20 77  | printf("hello w|
    00000030  6f 72 6c 64 5c 6e 22 29  3b 0a 20 20 72 65 74 75  |orld\n");.  retu|
    00000040  72 6e 20 30 3b 0a 7d 0a                           |rn 0;.}.|
    $ hexdump -e'"%07.8_ad  " 8/1 "%03d " "  " 8/1 "%03d " "  |"' -e'16/1  "%_p"  "|\n"' b.c
    00000000  035 105 110 099 108 117 100 101  032 060 115 116 100 105 111 046  |#include <stdio.|
    00000016  104 062 010 105 110 116 032 109  097 105 110 040 041 123 010 032  |h>.int main(){. |
    00000032  032 112 114 105 110 116 102 040  034 104 101 108 108 111 032 119  | printf("hello w|
    00000048  111 114 108 100 092 110 034 041  059 010 032 032 114 101 116 117  |orld\n");.  retu|
    00000064  114 110 032 048 059 010 125 010                                   |rn 0;.}.|
    

    不确定如何重现-C 生成的最后一行。

    更多详情请见here

    【讨论】:

    • 最后一行将通过添加-e '"%07.8_Ad\n"'产生。
    • 完美!谢谢弗拉德!
    猜你喜欢
    • 2013-03-31
    • 2011-12-09
    • 2011-06-01
    • 2016-06-18
    • 2018-07-26
    • 1970-01-01
    • 2014-04-18
    • 2014-11-30
    相关资源
    最近更新 更多