Friday, July 29, 2011

awk script to find min and max value in a text file

awk 'BEGIN {min=100};  { for (i=1; i< min) {min = $i; print $i } } }; END {print min} ' $filename

print tokens in all lines:
awk '{for (i=1; i<=NF; i++ ) print $i}'

bash script to replace all spaces with +
ls > blah;
while read line; do a=`echo ${line// /+}`;
mv "$line" $a;
done < blah;
rm blah;

bash script to upper to lower case file names
for i in `ls *`; do echo $i > blah; g=`tr '[A-Z]' '[a-z]' < blah`; mv $i $g ; rm blah; done


bash script to give info about all wav files in a dir
for i in `ls *.wav`; do soxi $i  ; done


bash script to resample wav files in a dir to 16000 Hz
for i in `ls *.wav`; do tmp=${i}tmp ; mv $i $tmp ; sox $tmp -r 16000 $i ; done

bash script to change all wav files in a dir to mono
 for i in `ls *.wav`; do tmp=1${i} ; mv $i $tmp ; sox $tmp -c 1 $i ; rm $tmp ; done

bash script to process all wav files in a dir with jaudio: For files A.wav, B.wav returns, A.arff, B.arff

cd /Applications/jAudio/;
for i in `ls /Volumes/SAMSUNG/COMPARISONGDB/testDatabase/newQueries_SUN/*.wav`;
do
a=`basename $i .wav`;
b=/Volumes/SAMSUNG/COMPARISONGDB/testDatabase/newQueries_SUN/${a};
  java -Xmx1024M -jar /Applications/jAudio/jAudio.jar -s /Applications/jAudio/settingsRMS.xml $b $i ;
done

for i in `ls *.arff`; do a=`basename $i .arff`; tail -n +5 $i > ${a}.RMS ; rm $i; done

% parse stm files and generate matchesGT files
for i in `ls *.stm`; do a=`basename $i .stm`;   awk '{if ($2==1 && NF == 7) print $4"\t"$5 }' $i > ${a}.matchesGT; done

No comments: