********
Find a string within a file in a directory:
grep -ril “string” dir
********
Rename files:
for f in *; do ext=””; [[ $f =~ \. ]] && ext=”.”${f#*.}; mv “$f” “${f%%.*}”_NO$ext; done
or
ls -1 *_bla_* | awk -F”_” -v old=”bla” -v new=”newBla” ‘$2==old{print “mv “$0 ” “$1″_”new”_”$3}’ | sh
********
Move inner files to outer directory
find . -maxdepth 2 -type f -exec mv {} .. \;
********
replace a word in all files within a directory
sed -i ‘.old’ ‘s/phonation/vowels/g’ *.textgrid
********
delete part of the name of a file:
for file in *_auto.TextGrid ; do mv “$file” “${file%_auto.TextGrid}.TextGrid” ; done
********
change the extension of a list of files
for old in *.old; do mv $old `basename $old .old` ; done
********
Convert PDF files to PS
for f in *.pdf; do gs -sDEVICE=ps2write -dNOPAUSE -dBATCH -sOutputFile=./psFigures/$f.ps $f; done
********
select N random lines from a file:
brew install coreutils
gsort -R input | head -n 100 >output
***********
Make a smaller file:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed.pdf input.pdf
***********
Add something to the path:
echo $PATH
export PATH=$PATH:/usr/local/include/faust
************
Tricks with Sox
for i in *.wav; do /Applications/sox/sox $i equalLengthRecordings/$i trim 0 0.5275; done
for i in *.wav; do /Applications/sox/sox
$i ~/Desktop/$i fade 0 0.5275 0.01; done
for i in *.wav; do /Applications/sox/soxi -s $i; done
for i in *.wav; do /Applications/sox/sox $i ~/Desktop/$i rate 44100; done
************
Tricks with ffmpeg
for j in *.m4a; do /Applications/ffmpeg -i “$j” -acodec libmp3lame -ab 320k ../mp3/”$j”.mp3 ; done
for file in *.m4a.mp3 ; do mv “$file” “${file%.m4a.mp3}.mp3” ; done
************
Search LaTeX Documentation:
texdoc library_name
************
Find the binding box of a ps
gs -sDEVICE=bbox -dNOPAUSE -dBATCH file