#! /bin/bash

if [ $# != 2 ]
then
	echo "error use $0. Right use this script: "
	echo "$0 path_to_file data_type (flight or KDI)"
	echo "example 1: $0 ./data/flight/30_12_2024/ASOTR_1_SOTR_T flight"
else
	data_file=$1
	data_type=$2

	if [ "$data_type" == "flight" ]
	then	
		cat ${data_file}.csv | grep -Eo '[0-9]{2}\.[0-9]{2}\.[0-9]{4}' > file1
		cat ${data_file}.csv | grep -Eo [0-9]{2}:.* > file2
		
	elif [ "$data_type" == "KDI" ]
	then
		cat ${data_file}.csv | grep -Eo [0-9]{2}.[0-9]{2}.[0-9]{4} > file1
		cat ${data_file}.csv | grep -Eo [0-9]{2}:.* > file2
	else
		echo "error argument of data_type: write \"flight\" or \"KDI\" in second argument"
		exit 1
	fi
	
	paste --delimiter=' ' file1 file2 > file.csv
	echo "timestamp;ch1;ch2;ch3;ch4;ch5;ch6" > ${data_file}_clear.csv
	cat file.csv >> ${data_file}_clear.csv
	rm file1 file2 file.csv
fi
