I have a bash script which outputs some statistics on the screen for each sample number(example shown below) when I run the test.sh code.
What I am trying to do is that to store the output in a variable and extract the Mean value for a testNum --> 11 and 52
A=`./test.sh` # I have all the output in a variable A
Now I need to extract the mean value of 11 which is -128 and -96 for 52 I'm trying and thinking How I can do this
Can anyone help me in this please ?
This is the example test code : test.sh
#!/bin/sh
echo Valid Numbers per States:3G phones
echo testNum N_States Mean Value
echo 1 10 -128
echo 2 10 -95
echo 3 10 -94
echo 4 10 -94
echo 5 10 -94
echo 6 10 -128
echo 7 10 -91
echo 8 10 -94
echo 9 10 -94
echo 10 10 -94
echo 11 10 -128
echo --------------------------------------------
echo Valid Numbers per States :4G phones
echo testNum N_States Mean Value
echo 36 10 -95
echo 40 10 -95
echo 44 10 -95
echo 48 10 -95
echo 52 10 -96
echo 56 10 -95
echo 60 10 -96
echo 64 10 -96
echo 100 10 -99
echo 104 10 -97
echo 108 10 -98
echo 112 9 -98
echo 116 9 -98
echo 120 9 -99
echo 124 9 -98
echo 128 9 -98
echo 132 9 -98
echo 136 9 -99
echo 140 9 -99
echo 144 9 -99
echo 149 9 -98
echo 153 9 -99
echo 157 9 -99
echo 161 9 -99
echo 165 9 -98
echo --------------------------------------------
I have used the commands echo "$x" | grep -w '^52' | cut -d' ' -f3
But Linux on my proprietary hardware doesn't allow ^ (not sure if its version or something) .. I can run this on any bash shell..works fine, but if I run the same command, it doesn't output anything.
So I started doing some awk on it
Here temp is 128
NF_Est is output of the script
echo "$NF_Est" | grep -w 128 | awk '{if ($1==128)print $0}' | tr -s " " | cut -d" " -f3
But this is not working if I am the "temp" values in multiple columns
Any suggestions where I am messing up (or) this can be done in a much simpler way?
A=$(./test.sh)^? Does the computer crash or catch fire, or do you get a syntax error, or do you not have a keyboard with this symbol? Even if the system is proprietary, it almost certainly has a^character.