从Hive输出日志

时间:2017-04-26 15:31:12

标签: regex bash grep

我有Hive的输出。我将该输出存储在名为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值,知道它可能是任何其他数字?

2 个答案:

答案 0 :(得分:2)

您可以将server <- function(input, output) { points <- reactive ({ if (input$question1 == TRUE) { filtered2 <- filter(dataset, col.data == 1) select_(dataset, ~lng, ~lat) } }) output$map <- renderLeaflet({ leaflet(dataset) %>% addTiles() %>% setView(-77.33, 35.5881, 7) addMarkers(points()) }) } (空间管道空间)视为字段分隔符并打印第六个字段,如下所示:

 | 

请注意管道has to be escaped twice

旁注:

awk -F ' \\| ' '{ print $6 }'

可以改写为

echo $(echo $match | grep "COUNT_TOTAL_MATCH")

grep 'COUNT_TOTAL_MATCH' <<< "$match" 中没有echo,没有管道,也没有分词。 $match始终与echo "$(command)"相同。 (请注意,引用会有所不同。)

这意味着您可以将grep和awk命令组合到此:

command

答案 1 :(得分:1)

尝试

grep -oP 'COUNT_TOTAL_MATCH\h*\|\h*\K\d+'
  • \h*\|\h*可选空格/标签后跟|,后跟可选空格/标签
  • \K是积极的背后......所以只有匹配COUNT_TOTAL_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.
相关问题