I am writing a bash shell script that has to do multiple things. The function I am currently working on needs to transpose a matrix, which in this case is just a text file that has Rows and Columns. I have two files that I call m1 and m2... m1 text file is just this :
1 2 3
4 5 6
m2 =
1 5
2 6
3 7
4 8
So essentially I need to make m2 into m1 and m1 into m2. Here is my code so far, which I got most of it from an in-class lecture on transposing which helped a lot. It is currently not printing out anything but it still runs and doesn't have run time errors.
Here is my code:
transpose)
inputFile="tempinputfile"
tempCol="tempcolfile"
tempRow="temprowfile"
echo -e "1\t2\t3\t4\t5" > $inputFile
cut -c 1 $inputFile > $tempCol
cut -c 3 $inputFile >> $tempCol
cut -c 5 $inputFile >> $tempCol
cut -c 7 $inputFile >> $tempCol
cut -c 9 $inputFile >> $tempCol
cat $tempCol | tr '\n' '\t' > "$tempRow$$"
echo >> "$tempRow$$"
;;