UNIX Part III: Process Data with a Vengeance Consider the following data, format
ID: 3732723 • Letter: U
Question
UNIX
Part III: Process Data with a Vengeance
Consider the following data, formatted in the previous lab as shown below:
F gge0001x gge0001y gge0001z
D 12-30-2006 12-30-2006 12-30-2006
T 14:15:20 14:15:55 14:16:27
S a69 a69 a69
B 15.8 16.1 15
M gge06001 gge06001 gge06001
P 30.1 29.6 29.9
Q 20.2 22.3 23.4
R 1006.2 1003.5 999.8
U 1011.8 1011.8 1005
X 34.7 35.2 35.1
A 38.994 38.994 38.994
G 107.71 107.71 107.71
H 8.395 8.406 8.368
O 37.141 36.823 36.621
C 7.55 7.532 7.437
K 28.193 27.902 27.856
W 212.86 210.15 207.15
L 68.3 67.9 67.6
Write a bash script named lab4.3.sh will process this data file to determine the average performance output of the module. Upon processing, the data is to be presented as shown in the table below:
Performance Data
Date 12/30/2006
Tamb (°C) 15.63
Tref (°C) 29.87
Tm (°C) 21.97
Irradiance (W/m^2) 1003.17
Isc (A) 8.39
Voc (V) 36.86
Imp (A) 7.51
Vmp (V) 27.98
Pm (W) 210.05
FF (%) 67.93
Note the corresponding rows:
Date D
Tamb B
Tref P
Tm Q
Irradiance R
Isc H
Voc O
Imp C
Vmp K
Pm W
FF L
Explanation / Answer
This work done in bash script. Used printf for formatting the output.
Below is the content of lab4.3.sh file.
#!/bin/bash
#Data file path
file="/tmp/data.txt"
echo "Performance Data"
while read -r line
do
IFS=' ' read -r -a data <<< "$line"
if [ "${data[0]}" == "D" ]; then
printf "Date %s " "${data[1]}"
fi
if [ "${data[0]}" == "B" ]; then
tot=$(echo ${data[1]} + ${data[2]} + ${data[3]} | bc)
printf "Tamb (°C) %.02f " "$(echo $tot / 3 | bc -l)"
fi
if [ "${data[0]}" == "P" ]; then
tot=$(echo ${data[1]} + ${data[2]} + ${data[3]} | bc)
printf "Tref (°C) %.02f " "$(echo $tot / 3 | bc -l)"
fi
if [ "${data[0]}" == "Q" ]; then
tot=$(echo ${data[1]} + ${data[2]} + ${data[3]} | bc)
printf "Tm (°C) %.02f " "$(echo $tot / 3 | bc -l)"
fi
if [ "${data[0]}" == "R" ]; then
tot=$(echo ${data[1]} + ${data[2]} + ${data[3]} | bc)
printf "Irradiance (W/m^2) %.02f " "$(echo $tot / 3 | bc -l)"
fi
if [ "${data[0]}" == "H" ]; then
tot=$(echo ${data[1]} + ${data[2]} + ${data[3]} | bc)
printf "Isc (A) %.02f " "$(echo $tot / 3 | bc -l)"
fi
if [ "${data[0]}" == "O" ]; then
tot=$(echo ${data[1]} + ${data[2]} + ${data[3]} | bc)
printf "Voc (V) %.02f " "$(echo $tot / 3 | bc -l)"
fi
if [ "${data[0]}" == "C" ]; then
tot=$(echo ${data[1]} + ${data[2]} + ${data[3]} | bc)
printf "Imp (A) %.02f " "$(echo $tot / 3 | bc -l)"
fi
if [ "${data[0]}" == "K" ]; then
tot=$(echo ${data[1]} + ${data[2]} + ${data[3]} | bc)
printf "Vmp (V) %.02f " "$(echo $tot / 3 | bc -l)"
fi
if [ "${data[0]}" == "W" ]; then
tot=$(echo ${data[1]} + ${data[2]} + ${data[3]} | bc)
printf "Pm (W) %.02f " "$(echo $tot / 3 | bc -l)"
fi
if [ "${data[0]}" == "L" ]; then
tot=$(echo ${data[1]} + ${data[2]} + ${data[3]} | bc)
printf "FF (%%) %.02f " "$(echo $tot / 3 | bc -l)"
fi
done < "$file"
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.