免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: sofs
打印 上一主题 下一主题

perl 怎么以16进制操作文件,替换文件内容? [复制链接]

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
1 [报告]
发表于 2016-08-15 23:31 |显示全部楼层
回复 1# sofs

$ perl -pe 'BEGIN{$/=undef}{s/\x48\x5c\x00\x00\x00\x00\x00\x00\x03\x80.*//gs}' file.gz | hexdump -C
00000000  0f c9 50 a6 a2 e5 00 a2  e3 38 05 05 d3 5e 15 a9  |..P......8...^..|
00000010  32 b7 a0 00 b0 69 30 a5  43 2f 07 ef f8 73 5c 1a  |2....i0.C/...s\.|
...
000002d0  04 38 00 1f ea 00 30 4c  1a 2f 16 dd 6f ed d8 0c  |.8....0L./..o...|
000002e0  a1 f4 14 26 0d 80 33 80  5d a7                    |...&..3.].|
000002ea

   

评分

参与人数 1信誉积分 +5 收起 理由
523066680 + 5 很给力!

查看全部评分

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
2 [报告]
发表于 2016-08-16 08:40 |显示全部楼层
本帖最后由 jason680 于 2016-08-16 08:42 编辑

回复 6# sunzhiguolu

    binmode FILEHANDLE, LAYER
    binmode FILEHANDLE
            Arranges for FILEHANDLE to be read or written in "binary" or
            "text" mode on systems where the run-time libraries distinguish
            between binary and text files. If FILEHANDLE is an expression, the
            value is taken as the name of the filehandle. Returns true on
            success, otherwise it returns "undef" and sets $! (errno).

            
            On some systems (in general, DOS- and Windows-based systems)
            binmode() is necessary when you're not working with a text file.

            For the sake of portability it is a good idea always to use it
            when appropriate, and never to use it when it isn't appropriate.
            Also, people can set their I/O to be by default UTF8-encoded
            Unicode, not bytes.

            ...

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
3 [报告]
发表于 2016-08-16 08:49 |显示全部楼层
回复 7# hztj2005

1. 无Win10
有Win8

2. in Windows
  Don't use it in Windows

* you need modify the code into a script file by yourself

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
4 [报告]
发表于 2016-08-16 23:13 |显示全部楼层
回复 11# sofs

$ awk 'BEGIN{RS="\x48\x5c\x5c\x00\x00\x00\x00\x00\x00\x03\x80"}{if(a!="")printf("%s",a);a=$0RT}' file.gz | hexdump -C
00000000  0f c9 50 a6 a2 e5 00 a2  e3 38 05 05 d3 5e 15 a9  |..P......8...^..|
00000010  32 b7 a0 00 b0 69 30 a5  43 2f 07 ef f8 73 5c 1a  |2....i0.C/...s\.|
...
000005c0  80 21 1a d3 40 7d 81 a0  3e c1 a7 48 5c 00 00 00  |.!..@}..>..H\...|
000005d0  00 00 00 03 80                                    |.....|
000005d5

   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP