tojson.sh (651B)
1 #!/bin/bash 2 reports=(*.txt) 3 pos=$(( ${#reports[*]} - 1 )) 4 last=${reports[$pos]} 5 echo -n '{' 6 for report in "${reports[@]}"; do 7 server=$(echo $report | sed 's/.txt//') 8 echo -n "\"$server\":" 9 lines=`grep -B 17 'Conversations Compliance Suite: ' $report | grep running | wc -l` 10 context=`echo $lines + 2 | bc` 11 echo -n '{' ; grep -B $context 'Conversations Compliance Suite: ' $report | head -n $lines | sed 's/running //' | sed 's/…//' | sed -e 's/ \{3,\}/\t\t/g' | awk -v lines="$lines" -F '\t\t' '{ printf "\"" $1 "\":\"" $2 "\""; if (NR != lines) printf "," }'; echo -n '}' 12 if [[ $report != $last ]]; then echo -n ','; fi; 13 done; 14 echo '}'