#!/bin/bash # TODO: use tail instead of cat where only the top of the file is needed # extract the multiplier of the matrix MUL=`cat $1 \ | egrep -o 'e\+[0-9]* \*' \ | tr -d 'e+ *'` if [ -z "$MUL" ]; then MUL=1 fi # get the number of cols COLS=`cat $1 \ | egrep '([:space:]*([01](\.[0-9]*){0,1})[:space:]*)+$' \ | tail -n1 \ | wc -w` # read the matrix, multiply to correct value and put it out cat $1 \ | egrep '([:space:]*([01](\.[0-9]*){0,1})[:space:]*)+$' \ | tr " " "\n" \ | egrep -v '^$' \ | while read; do echo $MUL '*' $REPLY done \ | bc \ | sed 's/\([0-9]\+\)\.0*/\1/' \ | ( I=1 while read; do if [ $I -eq $COLS ]; then echo "$REPLY" I=1 else echo -n "$REPLY," I=$(( $I + 1 )) fi done ) # old debug stuff #echo $MUL $COLS