blob: b5021a4fcb11897aa51c57dca0dfba133906ee4d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#!/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
|