打印在正则表达式匹配AWK [英] Print regexp matches in AWK
本文介绍了打印在正则表达式匹配AWK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法来打印一个正则表达式匹配(但只匹配的字符串)与AWK?
Is there a way to print a regexp match (but only the matching string) with AWK?
推荐答案
是,在 AWK
使用匹配()
函数,并给它可选的阵列参数( A
在我的例子)。当你这样做时,0个元素将是匹配的正则表达式的一部分
Yes, in awk
use the match()
function and give it the optional array parameter (a
in my example). When you do this, the 0-th element will be the part that matched the regex
$ echo "blah foo123bar blah" | awk '{match($2,"[a-z]+[0-9]+",a)}END{print a[0]}'
foo123
这篇关于打印在正则表达式匹配AWK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文