Writing script to extract appropriate line from a web site using links
Hi,
I need to write a script called '~/get_birthrate' which when invoked with a two letter country abbreviation(i.e, au,ch,ni), extracts the appropriate line which contains the information about the country's birth rate from the URL http://www.cia.gov/library/publicati...k/geos/ca.html (where "ca.html" should be replaced with the appropriate two letter abbreviation). The output should look like: $ get_birthrate au 8.69 births/1,000 population (2007 est.) $ get_birthrate ch 13.45 births/1,000 population (2007 est.) $ get_birthrate ni 40.2 births/1,000 population (2007 est.) any help will really be appreciated... Thank you |
your link redirects
you need to use this kind of link "https://www.cia.gov/library/publications/the-world-factbook/geos/ca.html" https instead of http about your questions, not a very good way of doing this will be this Code:
[Ax@localhost ~]$ wget https://www.cia.gov/library/publications/the-world-factbook/geos/ca.html |
If you use -O with - you can pump it straight into grep, sed or awk and strip out what you like:
Code:
wget -O- https://www.cia.gov/library/publications/the-world-factbook/geos/ca.html | grep -oE "[^>]*births/1,000 population[^<]*" |
@grail Nice, I just tried this and it worked like a charm.
|
@grail wow, I didn't knew that. A very useful trick
|
All times are GMT -5. The time now is 02:40 PM. |