问题描述
我要处理此列表:(当然,这只是摘录.)
I want to process this list: (Of course this is just an excerpt.)
1 S3 -> PC-8-Set
2 S3 -> PC-850-Set
3 S3 -> ANSI-Set
4 S3 -> 7-Bit-NRC
5 PC-8-Set -> S3
6 PC-850-Set -> S3
7 ANSI-Set -> S3
这就是我所做的:
awk -F '[[:blank:]]+' '{printf ("%s ", $2)}' list
这就是我得到的:
现在我认为量词+
等同于{1,}
,但是当我将行更改为
Now I thought the quantifier +
is equivalent to {1,}
, but when I changed the line to
awk -F '[[:blank:]]{1,}' '{printf ("%s ", $2)}' list
我只有空白,整行显示为$ 1.
I got just blanks and the whole line was read to $1.
有人可以解释这种行为吗?我很感谢每一个答案!
Can someone explain this behaviour please? I'm thankful for every answer!
推荐答案
尝试
awk --re-interval -F '[[:blank:]]{1,}' '{printf ("%s ", $2)}' list
在正则表达式中允许间隔表达式(请参阅正则表达式运算符).现在,这是gawk的默认行为.尽管如此,这 该选项既保持向后兼容性,又用于 与--traditional
选项结合使用.
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.
这篇关于与awk一起使用的正则表达式中的量词表现出意外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!