我有一個巨大的logfile1(Linux),日期格式如下&我想提取過去24小時的數據&用shell腳本寫入不同的文件。請幫我完成任務?Shell腳本(提取最近24小時的日誌)
----------
03/03/2016 05:40:42 AM QWTRAB1 AMQ7315: Failed to put message to accounting queue. Reason(2053
----------
03/03/2016 05:40:42 AM QWTRAB1 AMQ7315: Failed to put message to accounting queue. Reason(2053
----------
03/03/2016 05:40:46 AM QWTRAB1 AMQ7315: Failed to put message to accounting queue. Reason(2053
----------
03/03/2016 05:40:46 AM QWTRAB1 AMQ7315: Failed to put message to accounting queue. Reason(2053
./test.sh + $的awk'BEGIN {\ n個分割( 「一月二月三月四月五月六月七月八月九月十月十一月十二月」,月,「「)\ n作爲(一= 1; a <= 12; a ++)\ nm [months [a]] = a \ n} \ n {\ n split($ 4,array,「[:/]」); \ n year = array [3] \ n month = sprintf(「%02d」,m [array [2]])\ n \ n print> /apphome/mqm/logs/NewFile"-"year"_"month".txt"\n}'/ apphome/mqm/logs/MQLOGS.OUT.0303160800.txt awk:cmd。行:10:(FILENAME =/apphome/mqm/logs/MQLOGS.OUT.0303160800.txt FNR = 1)致命:除零試圖 – Krishna
@Krishna,我已經更新了我的答案。如果您的日誌文件中真的有'------'行,您必須先將它們過濾出來... – MaxU