[英]awk regex and space inside
Why my awk script 为什么我的awk脚本
BEGIN {
FS = "][ \t\v]+"
}
# Note space after + in the end of the regex.
NF == 2 && $1 ~ /[:alpha:][:digit:]+ / {
print $1, "<<<";
}
Doesn't match any string in the file like the following: 与文件中的任何字符串都不匹配,如下所示:
I1130 15:18:42.526808 17329 thrift_bridge.cpp:126] AAA
E1130 15:18:42.527042 16076 thrift_bridge.hpp:288] BBB
But if I remove space, both lines are in the output. 但是,如果我删除空间,则两行都在输出中。
It's because your character class syntax is wrong: 这是因为您的字符类语法错误:
/[[:alpha:]][[:digit:]]+ /
Without square brackets [:alpha:]
and [:digit:]
aren't seen like pre-defined POSIX character classes but like basic classes. 如果没有方括号, [:alpha:]
和[:digit:]
不会像预定义的POSIX字符类一样出现,而像基本类一样。
/[:alpha:][:digit:]+/
is the same than /[ahlp:][dgit:]+/
, and matches p:
on each line. /[:alpha:][:digit:]+/
与/[ahlp:][dgit:]+/
,并在每行上匹配p:
/[ahlp:][dgit:]+/
As @John1024 noticed it, mawk doesn't support POSIX character classes, so you must write: 正如@ John1024注意到的那样,mawk不支持POSIX字符类,因此您必须编写:
/[a-zA-Z][0-9]+ /
or use gawk since it is available under linux. 或使用gawk,因为它在Linux下可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.