Regex Grep配置单元输出日志的结果
我有一个来自蜂巢的输出。我将该输出存储在名为Regex Grep配置单元输出日志的结果,regex,bash,grep,Regex,Bash,Grep,我有一个来自蜂巢的输出。我将该输出存储在名为match的变量中 我正在使用下面的命令从日志中隔离所需的行 echo $(echo $match | grep "COUNT_TOTAL_MATCH") 0: jdbc:hive2://hiveaddress> . . . . . . . . . . . . . . . . . . . . . . .> +--------------------+-------+--+ | stats | _c1 | +----------------
match
的变量中
我正在使用下面的命令从日志中隔离所需的行
echo $(echo $match | grep "COUNT_TOTAL_MATCH")
0: jdbc:hive2://hiveaddress> . . . . . . . . . . . . . . . . . . . . . . .> +--------------------+-------+--+ | stats | _c1 | +--------------------+-------+--+ | COUNT_TOTAL_MATCH | 1000 | +--------------------+-------+--+ 0: jdbc:hive2://hiveaddress> 0: jdbc:hive2://hiveaddress>
如果知道1000
值可能是任何其他数字,如何获取该值?试试看
grep -oP 'COUNT_TOTAL_MATCH\h*\|\h*\K\d+'
可选空格/制表符后接\h*\\\h*
可选空格/制表符
是正向查找。。。因此,只有当\K
匹配时COUNT\u TOTAL\u MATCH\h*\\h*
获取数字\d+
man grep
-o, --only-matching
Print only the matched (non-empty) parts of a matching line, with each such part on a separate output
line.
-P, --perl-regexp
Interpret the pattern as a Perl-compatible regular expression (PCRE). This is highly experimental and
grep -P may warn of unimplemented features.
试一试
可选空格/制表符后接\h*\\\h*
可选空格/制表符
是正向查找。。。因此,只有当\K
匹配时COUNT\u TOTAL\u MATCH\h*\\h*
获取数字\d+
man grep
-o, --only-matching
Print only the matched (non-empty) parts of a matching line, with each such part on a separate output
line.
-P, --perl-regexp
Interpret the pattern as a Perl-compatible regular expression (PCRE). This is highly experimental and
grep -P may warn of unimplemented features.
您可以将
|
(空格-管道-空间)视为字段分隔符并打印第六个字段,如下所示:
awk -F ' \\| ' '{ print $6 }'
请注意,该管道
旁注:
echo $(echo $match | grep "COUNT_TOTAL_MATCH")
可以重写为
grep 'COUNT_TOTAL_MATCH' <<< "$match"
您可以将
|
(空格-管道-空间)视为字段分隔符并打印第六个字段,如下所示:
awk -F ' \\| ' '{ print $6 }'
请注意,该管道
旁注:
echo $(echo $match | grep "COUNT_TOTAL_MATCH")
可以重写为
grep 'COUNT_TOTAL_MATCH' <<< "$match"
你的grep版本是什么?它是否支持
-P
?grep2.6.3。它支持-P
此外,我建议回显“$match”| grep“COUNT\u TOTAL\u match”
而不是您的代码。。。使用单引号,除非你需要shell解释…你的grep版本是什么?它是否支持-P
?grep2.6.3。它支持-P
此外,我建议回显“$match”| grep“COUNT\u TOTAL\u match”
而不是您的代码。。。并使用单引号,除非您需要shell对其进行解释。。。