I am new to shell scripting and would appreciate some help.
First some background - I want to display picture showing hosts around the world that have accessed a specific file on a server. All that is logged about the hosts is IP address - which is fine. From these IP addresses I can get a general idea of their location - again fine - via
http://api.hostip.info/ (a geolocator). Basically, this is to provide a quick visual. It doesn't need to be extremely detailed.
Now, the first part I can handle - converting IP address to Latitude/Longitude. This is done via the following script:
Code:
#!/bin/sh
touch output.txt
for line in $(< hosts);do
lynx -dump "http://api.hostip.info/rough.php?ip=$line&position=true" >> output.txt
done
exit 0
This outputs a file with the following format
Code:
Country: FRANCE
Country Code: FR
City: Paris
Latitude: 48.8
Longitude: 2.33333
Guessed: false
Country: UNITED STATES
Country Code: US
City: Bridgeport, CT
Latitude: 41.1863
Longitude: -73.1962
Guessed: true
This is where I am stuck. The only data I need from this format is the latitudes and the longitudes. Each lat/long pair needs to be on its own line. Example:
Code:
48.8 2.33333
41.1863 -73.1962
My question is: How do I pull just the latitude and longitude from output.txt and put them in the above format?
Thank you.
Recent comments
10 hours 26 min ago
13 hours 22 min ago
14 hours 35 min ago
15 hours 59 min ago
17 hours 37 min ago
19 hours 5 min ago
20 hours 19 min ago
1 day 12 hours ago
1 day 13 hours ago
1 day 16 hours ago