Quantifiers in a regular expression used with awk behave unexpected

﹥>﹥吖頭↗ 提交于 2019-12-01 23:34:34
Jotne

Try

awk --re-interval -F '[[:blank:]]{1,}' '{printf ("%s ", $2)}' list

--re-interval

Allow interval expressions (see Regexp Operators) in regexps. This is now gawk's default behavior. Nevertheless, this option remains both for backward compatibility, and for use in combination with the --traditional option.

You are using a Gawk which is from before this November 2010 commit, found by git bisect.

http://git.savannah.gnu.org/cgit/gawk.git/commit/?id=40b3741f63c19e38077d57f4ce4737916ec5073e

The change indeed hinges on the defaulting behavior with respect to intervals, which become on by default (as POSIX requires them to be).

It looks like the --re-interval option becomes relegated only for use with --traditional; i.e. that if --traditional is enabled, then support for {m,n} goes away, but can be selectively brought back with --re-interval.

In your version, {m,n} is unrecognized by default, with or without --traditional. This is true up to this commit:

commit 00ef0423acd97cb964a2bae54c93a03a8ab50e5e
Author: Arnold D. Robbins <arnold@******>
Date:   Fri Jul 16 14:55:10 2010 +0300

    Move to 3.1.8.

and you're behind that still, on 3.1.5.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!