用Shell精簡log文件(shell的字符串和文件操作)

當前目錄下有文件log,內容大致如下

2015-11-29 54144a04ad4asd044a4s CSeq:1 INVITE sip:2112@sipserver.com:5060 SIP/2.0
2015-11-29 54144a04ad4asd045457 CSeq:1 INVITE SIP/2.0 200 OK

將此log文件做精簡,創建文件minilog內容如下

1 INVITE sip:2112@sipserver.com:5060 SIP/2.0
1 INVITE SIP/2.0 200 OK

Shell腳本代碼如下

#!/bin/sh

function shortLog() {
  while read line
    do
      echo ${line#*CSeq:} >> $2
  done < $1
}

shortLog log miniLog
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章