December 5, 2018

Change your working directory to quiz2

There is a file quiz2.sh in your folder. You will edit it with nano

nano quiz2.sh

For each of the next questions, please write the corresponding commands after the question

If you like, you can open a second connection to the server

Write the awk command to show the first 5 lines of world_2007.txt

Afghanistan 31889923    Asia    43.828  974.5803384
Albania 3600523 Europe  76.423  5937.029526
Algeria 33333216    Africa  72.301  6223.367465
Angola  12420476    Africa  42.731  4797.231267
Argentina   40301927    Americas    75.32   12779.37964

Show the data between lines 45 and 50 (inclusive) of world_2007.txt

France  61083916    Europe  80.657  30470.0167
Gabon   1454867 Africa  56.735  13206.48452
Gambia  1688359 Africa  59.448  752.7497265
Germany 82400996    Europe  79.406  32170.37442
Ghana   22873338    Africa  60.022  1327.60891
Greece  10706290    Europe  79.483  27538.41188

Write the awk command to show the data corresponding to Turkey

Turkey  71158647    Europe  71.777  8458.276384

Write the awk command to find how many lines are there in world_2007.txt

142

How many countries are called “Rep”?

Write the command to find how many lines of world_2007.txt contain the exact word “Rep”, but not “Republic”

Congo,_Dem._Rep.    64606759    Africa  46.462  277.5518587
Congo,_Rep. 3800610 Africa  55.322  3632.557798
Korea,_Dem._Rep.    23301725    Asia    67.297  1593.06548
Korea,_Rep. 49044790    Asia    78.623  23348.13973
Yemen,_Rep. 22211743    Asia    62.698  2280.769906

Which is the African country with 135031164 habitants?

Nigeria 135031164   Africa  46.859  2013.977305

Write an awk command that prints population and country (in that order) when the continent is “Europa”

3600523 Albania
8199783 Austria
10392226 Belgium
4552198 Bosnia_and_Herzegovina
7322858 Bulgaria
4493312 Croatia
10228744 Czech_Republic
5468120 Denmark
5238460 Finland
61083916 France
82400996 Germany
10706290 Greece
9956108 Hungary
301931 Iceland
4109086 Ireland
58147733 Italy
684736 Montenegro
16570613 Netherlands
4627926 Norway
38518241 Poland
10642836 Portugal
22276056 Romania
10150265 Serbia
5447502 Slovak_Republic
2009245 Slovenia
40448191 Spain
9031088 Sweden
7554661 Switzerland
71158647 Turkey
60776238 United_Kingdom

Which are the countries with the biggest population in Europa?

Sort the output of the last command, from biggest to smallest

Use | and sort

82400996 Germany
71158647 Turkey
61083916 France
60776238 United_Kingdom
58147733 Italy
40448191 Spain
38518241 Poland
22276056 Romania
16570613 Netherlands
10706290 Greece
10642836 Portugal
10392226 Belgium
10228744 Czech_Republic
10150265 Serbia
9956108 Hungary
9031088 Sweden
8199783 Austria
7554661 Switzerland
7322858 Bulgaria
5468120 Denmark
5447502 Slovak_Republic
5238460 Finland
4627926 Norway
4552198 Bosnia_and_Herzegovina
4493312 Croatia
4109086 Ireland
3600523 Albania
2009245 Slovenia
684736 Montenegro
301931 Iceland

What is the ranking of Turkey’s population in Europe?

Take the sorted output of last command and pipe it into an awk command that prints the row number and the second field when the country is “Turkey”

2 Turkey 71158647

What is the ranking of Turkey’s GDP per capita in Europe?

Repeat the last command, changing “Population” for “GDP per capita”

28 Turkey 8458.276384

What is the ranking of Turkey’s Life expectancy in Europe?

Repeat the last command, changing “GDP per capita” for “Life Expectancy”

30 Turkey 71.777

How many countries are there in Europe?

Write an awk command that counts how many lines have “Europe” in the third field

30