我試圖從日誌輸出awk的多個分隔符和打印多列
實例日誌文件的兩行創建了一個CSV文件:
May 24 2013 18:13:24 ROUTER1 %%01IFNET/4/UPDOWN(l): The state of interface GigabitEthernet0/0/22 was changed to DOWN.
May 24 2013 17:59:33 ROUTER1 %%01FIB/3/REFRESH_END(l): FIB refreshing end, the refresh group map is 0!
預期輸出:
May 24 2013 18:13:24,ROUTER1,01IFNET,4,UPDOWN,The state of interface GigabitEthernet0/0/22 was changed to DOWN.
May 24 2013 17:59:33,ROUTER1,01IFNET,3,REFRESH_END,FIB refreshing end, the refresh group map is 0!
我可以通過這個awk命令設法得到幾個部分:
cat test.log | awk -F'[" "%%/(l)]' '{print $1" "$2" "$3","$4","$5","$8","$9","$10","}'
輸出:
May 24 2013 18:13:24,ROUTER1,01IFNET,4,UPDOWN,
May 24 2013 17:59:33,ROUTER1,01IFNET,3,REFRESH_END,
但我怎麼能捕捉到多列說明文字後「(1):」像「FIB清爽結束,刷新組映射爲0!「或」接口GigabitEthernet0/0/22的狀態變爲DOWN。 。」請告知
謝謝,正是我所需要的! – Rousseau
sudo_O,-F'[(/%]'匹配什麼? – jonschipp
'-F'用於設置數據分隔符,其中的值是一個正則表達式'[(/%]',它定義了一個包含字符的字符類''(''''''''''''或者單個空格。基本上任何類中的字符都不會被當作數據而是作爲分隔符。 –