case 4.1
Info for unit 1 starts now
info1
info2
info3
info5 - the one I want
info6
info7
Info for unit 2 starts now
info1
info2
info3
info5 - the one I want
info6
info7
endcase 4.1
The info for the 2 units are printed out over 1000 times in the file.
My algorithm is as follows:
while read line
do
if line contains unit1
then current_unit=1
if line contains unit2
then current_unit2
if line contains info5
then
if current_unit = 1
then unit1_val = *the relevant info from this line*
elif current_unit = 2
then unit2_val = *the relevant info from this line*
if both unit1_val > 20 && unit2_val > 20
then pass
Short version: pull the values i need, if at some point both values are over a certain value, test passed. I'm also trying to do this using Bash
Edit for clarity: The problem that I', having is passing variables in and out of if statements. My parsing and comparisons are fine, however When i get to the last if, the values are not there, because they are local to the if - fi they come from (or dont come from, as the case may be)
edit 2:
if [[ $line == *"info5"* ]]
then
CURRENT_UNIT=5
fi
if [[ $line = *"info6"* ]]
then
CURRENT_UNIT=6
fi
if [[ $line =~ "text i want" ]]
then
if [[ $CURRENT_UNIT -eq 5 ]]
then
UNIT_5_MEM=$(awk '/Used heap/ { gsub(/M/, " "); print $4 }')
elif [[ $CURRENT_VC -eq 6 ]]
then UNIT_6_MEM=$(awk '/Used heap/ { gsub(/M/, " "); print $4 }')
fi
fi
if [[ $UNIT_5_MEM -gt 20 && $UNIT_6_MEM -gt 20 ]]
then
echo "Passed"
fi