-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquakes.sh
executable file
·42 lines (36 loc) · 1.06 KB
/
quakes.sh
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
#!/usr/bin/env bash
#
# query usgs web service with curl and print latest earthquakes greater than 2.5
howlong='day'
sortmag=false
helpmsg=false
verbose=false
while getopts 'Hshv' flag; do
case "${flag}" in
H) howlong='hour' ;;
s) sortmag=true ;;
h) helpmsg=true ;;
v) verbose=true ;;
*) error "Unexpected option ${flag}" ;;
esac
done
if $helpmsg; then
echo NAME
echo 'quakes -- use curl to call usgs earthquake (greater than 2.5M) feed'
echo
echo OPTIONS
echo -h display this help message
echo -H only show earthquakes in the past Hour, default is Day
echo -s sort by magnitude, header removed
echo -v print feed url
exit
fi
url='http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_'
ext='.csv'
if $verbose; then
echo $url$howlong$ext
fi
if $sortmag;
then curl -s $url$howlong$ext | sed 's/, / - /g' | cut -d, -f 1-5,14 | column -s, -t | tail +2 | sort -n -k 5,5 -r
else curl -s $url$howlong$ext | sed 's/, / - /g' | cut -d, -f 1-5,14 | column -s, -t
fi