免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3503 | 回复: 3
打印 上一主题 下一主题

[学习共享] GNU sed 的 debug 选项, 助你了解sed的执行流程 [复制链接]

论坛徽章:
60
20周年集字徽章-20	
日期:2020-10-28 14:04:3015-16赛季CBA联赛之北京
日期:2016-07-06 15:42:0715-16赛季CBA联赛之同曦
日期:2016-06-12 10:38:0915-16赛季CBA联赛之佛山
日期:2016-05-27 11:54:56黄金圣斗士
日期:2015-12-02 11:44:35白银圣斗士
日期:2015-11-25 14:32:43白银圣斗士
日期:2015-11-23 12:53:352015亚冠之布里斯班狮吼
日期:2015-10-21 16:55:482015亚冠之首尔
日期:2015-09-01 16:46:052015亚冠之德黑兰石油
日期:2015-08-31 11:39:192015亚冠之萨济拖拉机
日期:2015-08-28 21:06:5315-16赛季CBA联赛之广东
日期:2016-07-12 14:58:53
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2019-09-27 18:04 |只看该作者 |倒序浏览
曾以何时有个 sedsed 的 sed 调试工具, 用的好不欢喜
这两天无意间看了下 sed 的更新历史, 在GNU sed 4.6 版本中, 发现新增了一个 --debug 选项, 试用了一下, 一个字: 好
大家伙可以试试

  1. NEWS

  2. * Noteworthy changes in release 4.6 (2018-12-19) [stable]

  3. ** Improvements

  4.   sed now prints a clear error message when r/R/w/W (and s///w) commands
  5.   are missing a filename. Previously, w/W commands would fail with confusing
  6.   error message, while r/R would be a silent no-op.

  7.   sed now uses fully-buffered output (instead of line-buffered) when
  8.   writing to files. This should noticeably improve performance of "sed -i"
  9.   and other write commands.
  10.   Buffering can be disabled (as before) with "sed -u".

  11.   sed in non-cygwin windows environments (e.g. mingw) now properly handles
  12.   '\n' newlines in -b/--binary mode.

  13. ** Bug fixes

  14.   sed no longer accesses invalid memory (heap overflow) when given invalid
  15.   backreferences in 's' command [bug#32082, present at least since sed-4.0.6].

  16.   sed no longer adds extraneous NUL when given s/$//n command.
  17.   [related to bug#32271, present since sed-4.0.7]

  18.   sed no longer accesses invalid memory (heap overflow) with s/$//n regexes.
  19.   [bug#32271, present since sed-4.3].

  20. ** New Features

  21. New option, --debug: print the input sed script in canonical form
  22.   and annotate program execution.
复制代码

New option, --debug: print the input sed script in canonical form
  and annotate program execution.


  1. $ seq 3 | sed --debug -e 's/./--&--/ ; 2d'
  2.     SED PROGRAM:
  3.       s/./--&--/
  4.       2 d
  5.     INPUT:   'STDIN' line 1
  6.     PATTERN: 1
  7.     COMMAND: s/./--&--/
  8.     MATCHED REGEX REGISTERS
  9.       regex[0] = 0-1 '1'
  10.     PATTERN: --1--
  11.     COMMAND: 2 d
  12.     END-OF-CYCLE:
  13.     --1--
  14.     INPUT:   'STDIN' line 2
  15.     PATTERN: 2
  16.     COMMAND: s/./--&--/
  17.     MATCHED REGEX REGISTERS
  18.       regex[0] = 0-1 '2'
  19.     PATTERN: --2--
  20.     COMMAND: 2 d
  21.     END-OF-CYCLE:
  22.     INPUT:   'STDIN' line 3
  23.     PATTERN: 3
  24.     COMMAND: s/./--&--/
  25.     MATCHED REGEX REGISTERS
  26.       regex[0] = 0-1 '3'
  27.     PATTERN: --3--
  28.     COMMAND: 2 d
  29.     END-OF-CYCLE:
  30.     --3--
复制代码




论坛徽章:
0
2 [报告]
发表于 2019-09-27 19:12 |只看该作者
确实不错哦。

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
3 [报告]
发表于 2019-10-10 09:37 |只看该作者
Beautiful

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
4 [报告]
发表于 2019-11-07 15:36 |只看该作者
感谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP