2014-10-03 47 views
-1

我有一個日誌文件,可以收到最多8k字節的消息。我希望這些消息更小。我目前使用tail -c +1 -F跟蹤日誌文件,但是這抓住了整個8k消息,這是巨大的。我想要做一些像tail -c 2048 -F但是我不想丟失和消息的文本。請問tail -c 1024 -F如果msg超過1024字節,會導致我丟失一些msg信息?tail'-c'參數是否僅返回該行的指定字節數?或者它會以-c字節塊的形式返回整行?

附加信息: 如果消息太大,我正在調用python的tail命令和我的正則表達式過濾滯後。

for line in sh.tail("-c", "4096", "-F", path, _iter=True): 
    # Doing some regex filtering here 
+0

什麼對象有「尾部」方法? – chepner 2014-10-03 19:35:13

+0

從你可以在代碼中看到的*,你不是「從python調用尾部命令」,而是將一些參數傳遞給'sh'對象的'tail'方法。 – 2014-10-03 21:20:24

+0

'sh'是一個允許調用某些系統程序的包。以下是文檔:http://amoffat.github.io/sh/# – steve 2014-10-03 21:35:24

回答

-1

tail -n +2打印從第二行到結尾的所有內容。 你正在尋找的是tail -n 2或更短:tail -2這將採取最後兩行。

相同的模式適用於字節:

由於man tail說:

-c, --bytes=K output the last K bytes; alternatively, use -c +K to output bytes starting with the Kth of each file

RTFM?

+0

我的unix系統上的文檔與您的文檔不一樣,並且看起來不像描述性文檔。 – steve 2014-10-03 21:38:45

+0

http://www.gnu.org/software/coreutils/manual/coreutils.html#tail-invocation && http://linux.die.net/man/1/tail下一次請說明你是什麼unix味道使用,例如gnu/linux和solaris之間存在細微的差異 – 2014-10-03 21:49:36