#!/bin/bash

#tar bz2 version

TMP_DIR=$(mktemp -d)

cd $TMP_DIR

for sn in $(find "${1}" -name *.7z)
do
        sn_dir=${sn%/*}
        fn=$(basename $sn)
        fn_pref=${fn:3:15}
        #echo processing $sn
        #pbzip2 -dc $sn | tar x
	7za e $sn *.txt
        #gps_trig=$(grep "Trigger at:" ${fn_pref}.txt | cut -d" " -f3)
        #usb_trig=$(grep "USB trig at:" ${fn_pref}.txt | cut -d" " -f4)
        #usb_trig2=$(grep "USB trig at:" ${fn_pref}.txt | cut -d" " -f4)
        #echo $fn $gps_trig $usb_trig
        #7za a ${fn}.7z *
        #mv ${fn}.7z ${sn_dir}
        cp *.txt ${2}
        rm -rf $TMP_DIR/*
done

rm -rf $TMP_DIR

