-1

I need to first grep the exact line and then to capture the required value.

eg.

Total logical records skipped:        0
Total logical records read:           500
Total logical records rejected:       3
Total logical records discarded:      0

I need to capture the value 500. How can i do that?

4

2 回答 2

1

一种使用方式awk

awk '/Total logical records read:/ { print $NF }' file.txt

如果通过捕获,您的意思是存储为 shell 变量:

variable=$(awk '/Total logical records read:/ { print $NF }' file.txt)
于 2012-09-27T07:25:16.580 回答
0

使用 grep + awk:

cat log.txt | grep read | awk '{print $ 5;}'

或者只是 awk:

cat log.txt | awk '/read/ {print $5;}'

查看这些示例:Awk 介绍教程 – 7 个 Awk 打印示例

于 2012-09-27T07:31:24.750 回答