split-speedtest1-script.sh 615 B

123456789101112131415161718
  1. #!/bin/bash
  2. # Expects $1 to be a (speedtest1 --script) output file. Output is a
  3. # series of SQL files extracted from that file.
  4. infile=${1:?arg = speedtest1 --script output file}
  5. testnums=$(grep -e '^-- begin test' "$infile" | cut -d' ' -f4)
  6. if [ x = "x${testnums}" ]; then
  7. echo "Could not parse any begin/end blocks out of $infile" 1>&2
  8. exit 1
  9. fi
  10. odir=${infile%%/*}
  11. if [ "$odir" = "$infile" ]; then odir="."; fi
  12. #echo testnums=$testnums
  13. for n in $testnums; do
  14. ofile=$odir/$(printf "speedtest1-%03d.sql" $n)
  15. sed -n -e "/^-- begin test $n /,/^-- end test $n\$/p" $infile > $ofile
  16. echo -e "$n\t$ofile"
  17. done