reyleon 发表于 2019-09-27 18:04

GNU sed 的 debug 选项, 助你了解sed的执行流程

曾以何时有个 sedsed 的 sed 调试工具, 用的好不欢喜
这两天无意间看了下 sed 的更新历史, 在GNU sed 4.6 版本中, 发现新增了一个 --debug 选项, 试用了一下, 一个字: 好
大家伙可以试试

NEWS

* Noteworthy changes in release 4.6 (2018-12-19)

** Improvements

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

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

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

** Bug fixes

sed no longer accesses invalid memory (heap overflow) when given invalid
backreferences in 's' command .

sed no longer adds extraneous NUL when given s/$//n command.


sed no longer accesses invalid memory (heap overflow) with s/$//n regexes.
.

** New Features

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

$ seq 3 | sed --debug -e 's/./--&--/ ; 2d'
    SED PROGRAM:
      s/./--&--/
      2 d
    INPUT:   'STDIN' line 1
    PATTERN: 1
    COMMAND: s/./--&--/
    MATCHED REGEX REGISTERS
      regex = 0-1 '1'
    PATTERN: --1--
    COMMAND: 2 d
    END-OF-CYCLE:
    --1--
    INPUT:   'STDIN' line 2
    PATTERN: 2
    COMMAND: s/./--&--/
    MATCHED REGEX REGISTERS
      regex = 0-1 '2'
    PATTERN: --2--
    COMMAND: 2 d
    END-OF-CYCLE:
    INPUT:   'STDIN' line 3
    PATTERN: 3
    COMMAND: s/./--&--/
    MATCHED REGEX REGISTERS
      regex = 0-1 '3'
    PATTERN: --3--
    COMMAND: 2 d
    END-OF-CYCLE:
    --3--



yexingqi 发表于 2019-09-27 19:12

确实不错哦。

Shell_HAT 发表于 2019-10-10 09:37

Beautiful:mrgreen:

waker 发表于 2019-11-07 15:36

感谢分享
页: [1]
查看完整版本: GNU sed 的 debug 选项, 助你了解sed的执行流程