我有一個日誌文件,我想用C程序在以下文件中打印以太網地址。那我該怎麼做?我的日誌文件如下:是否可以打印日誌文件的特定部分?
*Thu Dec 25 11:40:41 2014; ******** LAN traffic monitor started ********** LAN traffic log, generated Thu Dec 25 11:41:41 2014
Ethernet address: 08:00:27:d7:54:fa
Incoming total 389 packets, 184398 bytes; 388 IP packets
Outgoing total 383 packets, 64444 bytes; 382 IP packets
Average rates: 24.58 kbps incoming, 8.59 kbps outgoing
Last 5-second rates: 0.86 kbps incoming, 0.45 kbps outgoing
Ethernet address: 52:54:00:12:35:02
Incoming total 383 packets, 64444 bytes; 382 IP packets
Outgoing total 389 packets, 184398 bytes; 388 IP packets
Average rates: 8.59 kbps incoming, 24.58 kbps outgoing
Last 5-second rates: 0.45 kbps incoming, 0.86 kbps outgoing
Running time: 60 seconds
*** LAN traffic log, generated Thu Dec 25 11:42:41 2014
iEthernet address: 08:00:27:d7:54:fa
Incoming total 395 packets, 184935 bytes; 393 IP packets
Outgoing total 389 packets, 64805 bytes; 387 IP packets
Average rates: 12.33 kbps incoming, 4.32 kbps outgoing
Last 5-second rates: 0.00 kbps incoming, 0.00 kbps outgoing
Ethernet address: 52:54:00:12:35:02
Incoming total 389 packets, 64805 bytes; 387 IP packets
Outgoing total 395 packets, 184935 bytes; 393 IP packets
Average rates: 4.32 kbps incoming, 12.33 kbps outgoing
Last 5-second rates: 0.00 kbps incoming, 0.00 kbps outgoing
Running time: 120 seconds
歡迎來到Stack Overflow。請儘快閱讀[關於]頁面。請注意,您的問題含糊不清,因爲您尚未準確定義要從樣本數據中獲得的輸出(但您最好包含樣本數據)。展示你的嘗試也是一個好主意。目前還不清楚shell腳本是否足夠,或者你是否真的需要一個C程序。我希望在任務中使用'sed'或'grep',並在編寫C代碼完成這項工作之前使用'awk'或Perl或Python進行更復雜的處理。所有這些都是C程序;雖然它們不是自定義的C程序。 – 2014-12-27 22:05:01
如果你真的需要編寫C程序,正則表達式函數可能是有用的(參見你的系統上的'regcomp()','regexec()'等手冊頁)。 – kestasx 2014-12-27 23:36:49