#!/bin/bash for f in $(ls *.wav) do id=$(basename $f ".wav") dur=$(sox $f -n stat 2>&1 | sed -n 's#^Length (seconds):[^0-9]*([0-9.]*)$#1#p' | awk -F "." '{print $1}') expr $dur + 0 mid=$(( $dur / 2 )) sox $f ${id}_0_${mid}.wav trim 0 $mid sox $f ${id}_${mid}_${dur}.wav trim $mid $dur done