gpt4 book ai didi

regex - 与 awk 一起使用的正则表达式中的量词表现出意外

转载 作者:行者123 更新时间:2023-11-29 09:34:48 25 4
gpt4 key购买 nike

我要处理这个列表:(当然这只是摘录。)

    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)}' 列表

这是我得到的:

1 2 3 4 5 6 7

现在我认为量词 + 等同于 {1,},但是当我将行更改为

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

我得到的只是空白,整行被读到 $1。

有人可以解释一下这种行为吗?我感谢每一个答案!

enter image description here

最佳答案

尝试

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.

关于regex - 与 awk 一起使用的正则表达式中的量词表现出意外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20393781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com