我知道星號會以csv文件的形式創建自己的通話記錄。爲了我的目的,我需要格式化的通話記錄,如下所示。我使用:縮短sed命令 - 使用它製作星號通話記錄
ls -l /var/spool/asterisk/monitor
作爲我的通話記錄的基礎上,產生這樣的:
-rw------- 1 asterisk asterisk 112684 2013-02-07 17:24 20130207-172424-+15551235566-IN.wav
-rw------- 1 asterisk asterisk 44 2013-02-07 17:53 20130207-175311-+15554561122-IN.wav
-rw------- 1 asterisk asterisk 2019564 2013-02-07 18:00 20130207-175828-15554561122-OUT.wav
-rw------- 1 asterisk asterisk 44 2013-02-07 22:09 20130207-220805-15554561122-OUT.wav
-rw------- 1 asterisk asterisk 44 2013-02-07 22:12 20130207-221204-15551235566-OUT.wav
-rw------- 1 asterisk asterisk 111084 2013-02-07 22:13 20130207-221255-15551235566-OUT.wav
-rw------- 1 asterisk asterisk 364844 2013-02-07 22:39 20130207-223843-15558271212-OUT.wav
-rw------- 1 asterisk asterisk 4279404 2013-02-07 23:53 20130207-234836-5552785454-OUT.wav
-rw------- 1 asterisk asterisk 44 2013-02-08 00:00 20130208-000026-+15559813232-IN.wav
我需要幫助的部分是我下面的命令。它工作併產生我想要的確切結果;不過,這對我來說似乎很笨重。它可以縮短嗎?
變量
YESTER=$(date -d "-24 hours" +"%Y-%m-%d-%H%M")
TODAY=$(date +"%Y-%m-%d-%H%M_UTC")
創建呼叫日誌(命令我想改變)
ls -l /var/spool/asterisk/monitor/ |grep '\.wav'|awk '{print $8 " " $5/1000000}'|sed -e 's/4\.4e\-05/NOT RECORDED/g' -e 's/\.wav//g' -e 's/-/ /g' -e 's/OUT/OUT - Approx Minutes:/g' -e 's/IN/IN - Approx Minutes:/g' -e 's/\(\.[0-9]\).*$/\1/g' -e 's/^.\{15\}/& UTC -/' -e 's/^.\{13\}/&:/' -e 's/^.\{11\}/&:/' -e 's/^.\{6\}/&-/' -e 's/^.\{4\}/& /' -e 's/+//g' > /var/spool/asterisk/monitor/call_logs/${YESTER}__${TODAY}-call-log.txt
出於可讀性這裏是行分隔(沒有|)命令:
ls -l /var/spool/asterisk/monitor/
grep '\.wav'
awk '{print $8 " " $5/1000000}'
sed -e 's/4\.4e\-05/NOT RECORDED/g'
-e 's/\.wav//g'
-e 's/-/ /g'
-e 's/OUT/OUT - Approx Minutes:/g'
-e 's/IN/IN - Approx Minutes:/g'
-e 's/\(\.[0-9]\).*$/\1/g'
-e 's/^.\{15\}/& UTC -/'
-e 's/^.\{13\}/&:/'
-e 's/^.\{11\}/&:/'
-e 's/^.\{6\}/&-/'
-e 's/^.\{4\}/& /'
-e 's/+//g'
> /var/spool/asterisk/monitor/call_logs/${YESTER}__${TODAY}-call-log.txt
輸出:
2013 02-07 17:24:24 UTC - 15551235566 IN - Approx Minutes: 0.1
2013 02-07 17:53:11 UTC - 15554561122 IN - Approx Minutes: NOT RECORDED
2013 02-07 17:58:28 UTC - 15554561122 OUT - Approx Minutes: 2.0
2013 02-07 22:08:05 UTC - 15554561122 OUT - Approx Minutes: NOT RECORDED
2013 02-07 22:12:04 UTC - 15551235566 OUT - Approx Minutes: NOT RECORDED
2013 02-07 22:12:55 UTC - 15551235566 OUT - Approx Minutes: 0.1
2013 02-07 22:38:43 UTC - 15558271212 OUT - Approx Minutes: 0.3
2013 02-07 23:48:36 UTC - 5552785454 OUT - Approx Minutes: 4.2
2013 02-08 00:00:26 UTC - 15559813232 IN - Approx Minutes: NOT RECORDED
我對sed更加熟悉,但如果AWK更乾淨,我會提出建議。 – errorcode
但awk只允許以正確的格式打印。單個printf調用。 – arheops
這個很好用,謝謝! – errorcode