#!/bin/bash # usage: # octavescript2matlabscript *.m # # convert all Octave Scripts into MATLAB Scripts (translating # comments, endfunction) if [ $# -eq 0 ]; then echo "usage: octavescript2matlabscript *.m" exit fi for name in "$@"; do # only process scripts with relevant octave-only entries grep -q '\(^[ \t]*#.*\)\|endfunction\|endfor\|endif' "$name" if [ "${?}" -eq "0" ] ; then echo $name sed -i 's/^\([ \t]*\)##\(.*\)/\1%%\2/g;s/^\([ \t]*\)#\(.*\)/\1%\2/g;s/endfunction/end/g;s/endfor/end/g;s/endif/end/g' $name fi done