我正在使用awk從日誌文件中去除有用的信息。這是我的日誌文件看起來是這樣的:在這個awk命令中應該設置什麼?
2016-02-19 20:18:46,861 115971,100126017,524,523,1,[144115198332971054]
2016-02-19 20:18:46,874 95496,100126019,5,5,0,[]
2016-02-19 20:18:46,883 115974,100126025,57,57,0,[]
2016-02-19 20:18:46,891 115975,100126026,4,4,0,[]
2016-02-19 20:18:46,918 115976,100126027,122,122,0,[]
2016-02-19 20:18:47,688 115978,100126029,11656,11641,15,[144115198334490817,144115197319238988,144115197291063350,144115198332904743,144115197318718547,144115197319714394,144115197306930902,144115197250548791,144115198320676757,14411519
7253880518,144115197289305237,144115198083289344,144115197319697491,144115198273784435,144115198081583082]
2016-02-19 20:18:47,731 99590,100126032,12,12,0,[]
2016-02-19 20:18:47,832 115982,100126034,1397,1396,1,[144115198273784435]
2016-02-19 20:18:47,849 106705,100126035,31,31,0,[]
2016-02-19 20:18:47,860 107469,100126036,16,16,0,[]
2016-02-19 20:18:47,927 115983,100126037,824,824,0,[]
2016-02-19 20:18:47,985 115985,100126039,564,564,0,[]
2016-02-19 20:18:48,048 115986,100126040,338,338,0,[]
2016-02-19 20:18:48,108 115987,100126041,259,259,0,[]
2016-02-19 20:18:48,187 115989,100126043,693,692,1,[144115198273784435]
我用","
爲FS
變量;我需要[]
方括號中的全部內容,所以我試圖設置RS
爲"]"
:
awk 'BEGIN { FS=","; RS="]";} { print $2 ,$3, $6 ,$7}' removed-apply.log.2016-02-19
但結果是錯誤的:
861 115971 100126017 1 [144115198332971054]
874 95496 100126019 0 []
883 115974 100126025 0 []
891 115975 100126026 0 []
918 115976 100126027 0 []
688 115978 100126029 15 [144115198334490817
731 99590 100126032 0 []
832 115982 100126034 1 [144115198273784435]
849 106705 100126035 0 []
860 107469 100126036 0 []
927 115983 100126037 0 []
985 115985 100126039 0 []
048 115986 100126040 0 []
108 115987 100126041 0 []
187 115989 100126043 1 [144115198273784435]
看來RS
仍然是換行符。
TKS爲UR建議:d – JasonHuang
TNX用於取建議;-)很高興你有一個解決方案。祝你們好運。 – shellter