lundi 25 juillet 2016

Read file in array, if variable is zero do not output line

I have a file (extract below)

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

i want to read in this file and output the results to another file, changing Unix time to human readable - but i only want to do this if field 7 is populated.

#!/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"

The problem lies in my if statement, i get the error

./monitor_convert.sh: line 12: syntax error near unexpected token `done'
./monitor_convert.sh: line 12: ` done <"$file"'

My thinking in the if statement is that if field7=0 the go back to the reading the file into array, the done <"$file" bit. This is obviously incorrect, but i cannot work how to miss this line.

Thanks.

Aucun commentaire:

Enregistrer un commentaire