
如果我有一個每 5 分鐘更新一次記錄計數的文件,則輸出如下所示:
timestamp name of log file dataset record count 8600
timestamp name of log file dataset record count 8610
如何有效地隔離dataset record count XXXX
該字串並將其列印到螢幕上?
答案1
一種方法是使用 awk:
awk 'match($0, "dataset record count [[:digit:]]+") { print substr($0, RSTART, RLENGTH) }' input
或透過管道傳輸:
command | awk 'match($0, "dataset record count [[:digit:]]+") { print substr($0, RSTART, RLENGTH) }'
或使用接受的 grep -o
:
grep -Eo 'dataset record count [[:digit:]]+' input
或透過管道傳輸:
command | grep -Eo 'dataset record count [[:digit:]]+'