quarta-feira, 18 de junho de 2014

Making a LaTeX table out of matrix data on a text file

Ah, UNIX! I love you!

So after generating some data as a matrix with MATLAB, I ran with the problem of formatting it again but now for LaTeX. So I made this little bash script to solve my problem:



EXT=`echo $FILE | grep -o "\..*" | tail -n 1`
BASENAME=`basename $FILE $EXT`

cat $FILE | awk 'BEGIN{ ORS=""; OFS=""; } { for (i=1;i<=NF;i++) if (i<NF) print $i," & "; else print $i," \\\\ \n";;  }' > $BASENAME.tex

Hope it helps anyone out there