我有一個文件(下面提取)讀文件時,如果變量是零不輸出線
1468929555,4, 0.0000, 999999.0000, 0.0000,0,0,0,0,0
1468929555,5, 0.4810, 0.0080, 67.0200,0,4204,0,0,0
1468929555,6, 0.1290, 0.0120, 0.4100,0,16,0,0,0
1468929555,7, 0.0000, 999999.0000, 0.0000,0,0,0,0,0
我想在此文件中,並輸出結果到另一文件中讀取,改變Unix時間到人類可讀 - 但我只想在字段7填充時執行此操作。
#!/bin/bash
file="monitor_a.log"
host=`hostname`
while IFS=, read -r f1 f2 f3 f4 f5 f6 f7 f8 f9 f10
do
mod_time=`date -d @$f1 +"%d/%m/%y %H:%M:%S"`
if [[$f7=="0"]];
then
done <"$file"
fi
echo "$mod_time,300 ,$host, Apache-a, $f2 , $f5 , $f4 , $f3 , $f7 , $f8 , $f9 ,$f6, $f10" >> mod_monitor_a.log
done <"$file"
問題就出在我的if語句,我得到的錯誤
./monitor_convert.sh: line 12: syntax error near unexpected token `done'
./monitor_convert.sh: line 12: ` done <"$file"'
我的想法在if語句,如果字段7 = 0時,回到文件讀入陣,完成<「$ file」位。 這顯然是不正確的,但我不能工作如何錯過這一行。
謝謝。
在http://www.shellcheck.net/中粘貼腳本顯示問題:'if [[$ f7 ==「0」]]'是錯誤的,您需要括號內的空格。 – fedorqui