2011-03-14 89 views
3

我有一個活的日誌文件名爲log.log,想捕捉一些匹配模式和價值觀在裏面:tail -F log.log | grep ResponseTime |切-d = -f 2

舉例: log.log正在增長,我們正在尋找該行有模式 「RESPONSETIME = VALUE」,我們要提取匹配的值:

我執行:

tail -F log.log | grep ResponseTime | cut -d = -f 2 | tr -d " " 

而且我期待看到

VALUE1 
VALUE2 
.. etc 

但它不工作...我該怎麼辦?

謝謝 南無

===========

謝謝你,現在的工作。我正在使用: inotail -f log.log | stdbuf -oL grep ResponseTime | stdbuf -oL cut -d'='-f 2 | stdbuf -oL TR -d 「」

+0

什麼是你看到的,而不是:

我會tail如後只使用一個命令? – 2011-03-14 06:30:22

+0

如果運行'cat log.log |會發生什麼? grep ResponseTime | cut -d = -f 2 | tr -d「」'?我懷疑有些數據正在被緩存在流水線中,直到更多的數據被寫入'log.log'文件(或EOF)之前它纔會被刷新。 – srgerg 2011-03-14 06:35:32

回答

-2

如果你想刪除輸出中的新行,那麼你可以在任何如下:

| cut -d = -f 2|sed -e :a -e '$!N;s/\n//;ta' 

| cut -d = -f 2|tr -d '\n' 

| cut -d = -f 2|awk '{printf "%s",$0}' 
1

它不工作的原因是某些命令不會在每個輸出上刷新STDOUT。因此後面的命令永遠不會被傳遞。

tail -F t.log | sed '/ResponseTime/!d;s/ResponseTime\s+=\s+(\d+)/\\1/'