Diff

比較沒有時間戳的日誌

  • January 15, 2015

我有很多想要比較的日誌。問題是,一行中的前幾個字元是時間戳。如何比較日誌,忽略時間戳。

例如,這兩個應該是相同的:

httpd:debug:64.715:rutWan_getIpOrPppObjectByIfname:2124:looking for eth1
httpd:debug:64.717:rutWan_getIpOrPppObjectByIfname:2134:found WanIPConnection object
httpd:debug:64.719:odl_setObjectExternal:463:starting external set of WANIPConnection iidStack={3,1,6}
httpd:debug:64.719:rcl_wanIpConnObject:178:Entered
httpd:debug:64.719:rutCfg_tearDownWanIpConnection:365:Enter.
httpd:debug:64.719:rutWl2_getL2LinkObj:122:Enter.

和:

httpd:debug:328.628:rutWan_getIpOrPppObjectByIfname:2124:looking for eth1
httpd:debug:328.630:rutWan_getIpOrPppObjectByIfname:2134:found WanIPConnection object
httpd:debug:328.632:odl_setObjectExternal:463:starting external set of WANIPConnection iidStack={3,1,6}
httpd:debug:328.632:rcl_wanIpConnObject:178:Entered
httpd:debug:328.632:rutCfg_tearDownWanIpConnection:365:Enter.
httpd:debug:328.632:rutWl2_getL2LinkObj:122:Enter.

編輯: httpd 部分也可以不同,因為它是從庫中呼叫函式的程序的名稱。

您可以使用cut擺脫時間戳“列”

cat logfile | cut -d":" -f1,2,4- > logfile_notimestamp

如果您對這兩個文件都這樣做,您可以使用 diff 輕鬆比較它們。

引用自:https://unix.stackexchange.com/questions/179277