-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblemSet2.sh
More file actions
66 lines (53 loc) · 3.47 KB
/
Copy pathProblemSet2.sh
File metadata and controls
66 lines (53 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
#Copy the dataset to the current working directory and make a diretory for buffer files
cp /ufrc/zoo6927/share/Class_Files/data/flights.May2017-Apr2018.csv ./
mkdir ./buffer
#This part is for Q1
grep "Gainesville" flights.May2017-Apr2018.csv | cut -d "," -f 13,16 | grep -c 1.00 > Q1-answer.txt
cat Q1-answer.txt
echo -e "\n"
#This part is for Q2
##1.Generate the 1st row of the table
echo "GNV to:,Total flights,Total flights delayed(>15min),Total flights delayed due to Weather" | column -s ',' -t > Q2-table.txt
##2.Generate the 2nd row of the table
echo " ATL" > ./buffer/Q2-ATL.txt ###1st column, 2nd row, white spaces are used to place the text appropriately in the table
grep Gainesville flights.May2017-Apr2018.csv | grep -c '"FL","ATL"' >> ./buffer/Q2-ATL.txt ###count GNV-ATL flights
grep Gainesville flights.May2017-Apr2018.csv | grep '"FL","ATL"' | cut -d "," -f 13,16 | grep -c 1.00 >> ./buffer/Q2-ATL.txt ###count >15min delayed flights
grep Gainesville flights.May2017-Apr2018.csv | grep '"FL","ATL"' | cut -d "," -f 24 | grep -v ^$ | grep -vc 0.00 >> ./buffer/Q2-ATL.txt ###count weather delayed flights
cat ./buffer/Q2-ATL.txt | paste -sd "," | column -s ',' -t -o $'\t\t' >> Q2-table.txt ###change the multi-line output into the table format
##3.Generate the 3rd row of the table
echo " CLT" > ./buffer/Q2-CLT.txt ###1st column, 3rd row
grep Gainesville flights.May2017-Apr2018.csv | grep -c '"FL","CLT"' >> ./buffer/Q2-CLT.txt ###count GNV-CLT flights
grep Gainesville flights.May2017-Apr2018.csv | grep '"FL","CLT"' | cut -d "," -f 13,16 | grep -c 1.00 >> ./buffer/Q2-CLT.txt ###count >15min delayed flights
grep Gainesville flights.May2017-Apr2018.csv | grep '"FL","CLT"' | cut -d "," -f 24 | grep -v ^$ | grep -vc 0.00 >> ./buffer/Q2-CLT.txt ###count weather delayed flights
cat ./buffer/Q2-CLT.txt | paste -sd "," | column -s ',' -t -o $'\t\t' >> Q2-table.txt ###change the multi-line output into the table format
##4.Generate the 4th row of the table
echo " MIA" > ./buffer/Q2-MIA.txt ###1st column, 4th row
grep Gainesville flights.May2017-Apr2018.csv | grep -c '"FL","MIA"' >> ./buffer/Q2-MIA.txt ###count GNV-MIA flights
grep Gainesville flights.May2017-Apr2018.csv | grep '"FL","MIA"' | cut -d "," -f 13,16 | grep -c 1.00 >> ./buffer/Q2-MIA.txt ###count >15min delayed flights
grep Gainesville flights.May2017-Apr2018.csv | grep '"FL","MIA"' | cut -d "," -f 24 | grep -v ^$ | grep -vc 0.00 >> ./buffer/Q2-MIA.txt ###count weather delayed flights
cat ./buffer/Q2-MIA.txt | paste -sd "," | column -s ',' -t -o $'\t\t' >> Q2-table.txt ###change the multi-line output into table format
cat Q2-table.txt
echo -e "\n"
#This part is for Q3
Airport-code () {
cut -d "," -f 3 flights.May2017-Apr2018.csv | cut -d '"' -f 2 > ./buffer/buffer_Q3.txt
cut -d "," -f 7 flights.May2017-Apr2018.csv | cut -d '"' -f 2 >> ./buffer/buffer_Q3.txt
sort -u ./buffer/buffer_Q3.txt | grep -v "ORIG\|DEST" > Q3-answer.txt
cat Q3-answer.txt
}
Airport-code
echo -e "\n"
#This part is for Q4
FL-airport () {
grep ", FL" flights.May2017-Apr2018.csv > ./buffer/buffer_Q4-1.txt
cut -d '"' -f 4 ./buffer/buffer_Q4-1.txt > ./buffer/buffer_Q4-2.txt
cut -d '"' -f 10 ./buffer/buffer_Q4-1.txt >> ./buffer/buffer_Q4-2.txt
grep "FL" ./buffer/buffer_Q4-2.txt | cut -d "," -f 1 | sort -u > Q4-answer.txt
cat Q4-answer.txt
}
FL-airport
#Clean the dataset and buffer files
rm -r flights.May2017-Apr2018.csv ./buffer
##Cheers~
echo -e "\n\n"Done..."\n\n"We are The Bash Masters!