Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #if the number of arguments is not 2
- if [ $# -ne 2 ]
- then
- echo "USAGE: `basename $0` folder_from folder_to"
- exit 1
- fi
- #if an input.json file does not exist in source folder
- if [ ! -f $1/input.json ]
- then
- echo "Vleznata datoteka ne postoi"
- exit 1
- fi
- #if the destination folder does not exist
- if [ ! -d $2 ]
- then
- mkdir $2
- fi
- FROM=$1
- TO=$2
- #create our final output.csv file and a temp.txt file for input info manipulation
- touch output.csv
- touch temp.txt
- #include only the lines that consist double dot(info lines), then change global empty spacez, comaz and quotation markz with nothing
- echo `cat $FROM/input.json | grep : | sed -e 's/ //g' -e 's/,//g' -e 's/"//g'` >> temp.txt
- #get sum of all durations
- sum_duration=`cat temp.txt | grep ^duration | awk -F: 'BEGIN {total=0} {total+=$2} END {print total}'`
- #get number of lines that contain duration attribute
- number_of_audios=`cat temp.txt | grep ^duration | wc -l`
- #get average duration of an audio file
- average_duration=`expr $sum_duration / $number_of_audios`
- #instead of working with rows of one file, make a field with elements of each attribute
- FILEPATHS=`cat temp.txt | grep ^filepath | awk -F: 'print $2'`
- DURATIONS=`cat temp.txt | grep ^duration | awk -F: 'print $2'`
- FILESIZES=`cat temp.txt | grep ^filesize | awk -F: 'print $2'`
- count=0
- echo "id,filepath,filesize,is_longer" >> output.csv
- #do as many iterations of while as there are audio files
- while [ count -lt $number_of_audios ]
- do
- is_longer=0
- if [ ${DURATIONS[${count} -gt $average_duration ]
- then
- is_longer=1
- fi
- id_number=`expr $count + 1`
- echo "${id_number},${FILEPATHS[${count}]},${FILESIZES[${count}]},${is_longer}" >> output.csv
- count=`expr $count + 1`
- done
- #move the fucking file of interest
- mv output.csv $TO/output.csv
- cat $TO/output.csv
- #FINALLY ITS OVER
Add Comment
Please, Sign In to add comment