The problem statement, all variables and given/known data:
Hello!
I need help with this problem bash shell scripting that basically just reads the data in a tab delimited file and does the following below
Read in the data file Survey.txt and assign the column values to variables of your choosing.
Calculate the total number of survey respondents.
Calculate the ratio of male to female respondents.
Calculate the average Height and Weight of the male and female respondents and compare your results.
Calculate the average Verbal and Math scores of the right- and left-handed respondents and compare your results.
Relevant commands, code, scripts, algorithms:
Attached is the Survey.txt file that this script is going to be reading.
The attempts at a solution (include all code and scripts):
Here is the code that I have completed so far:
#!/bin/bash
IFS=$'\n'
for line in $(cat ./Survey.txt)
do
echo $line
done
Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Eastern Center For Arts and Technology Willow Grove PA USA Computer Network Administration Instructor Karon Crickmore
IFS is used to tell the shell what the field separator character is. \n is normally the record separator. The file has tab characters to separate the fields - how do you write a tab?
Hi, do you know what \n stands for and what \t stands for? Anyway I would forget about a for loop with a global IFS. I would look into while read loop in which you can also set IFS local to the read statement if need be, plus it gives the added possibility of reading more variables in on go...
Sex Math Verbal Height Weight Handed
male 640 470 71 210 left
female 660 650 65 135 right
male 550 580 68 145 right
female 560 660 67 135 right
female 600 790 69 164 right
female 560 640 71 175 right
female 550 660 64 120 left
female 600 560 63 103 right
female 540 560 67 150 right
female 540 540 65 130 right
female 600 620 64 140 right
male 670 640 74 175 left
female 680 550 64 135 right
Use a while loop to read the file. You now have all the values in 6 named variables that you can use to perform the math mentioned in your problem statement.
#!/bin/bash
while read sex math verbal height weight handed
do
[ "$sex" == "Sex" ] && continue # Skip the Header
echo $sex $math $verbal $height $weight $handed # Print values read in variable
done < survey.txt