web-dev-qa-db-fra.com

Comment extraire une table du vidage de liens?

Ce qui suit est un links -dump dont je veux extraire le tableau avec toutes les colonnes de tout le fichier ... J'ai essayé d'utiliser awk mais j'ai échoué

     * Home
          * Frontpage
     * Continents
          * Africa
          * The Americas
          * Asia
          * Europe
          * Oceania/Australia
     * Countries
          * Countries A to Z
          * Dependent Areas
          * Countries by Area
          * Country Population
          * Country Flags
          * Int'l Currencies
     * Cities
          * Megacities
          * Famous Cities
          * Capital Cities Africa
          * Capital Cities Americas
          * Capital Cities Asia
          * Capital Cities Australia
          * Capital Cities Europe
          * US Capital Cities
          * Largest US cities
     * Landmarks
          * City Icons
          * Places of Power
          * Sacred Mountains
     * Languages
          * Languages by countries
          * Language codes
          * Most spoken Languages
     * Maps
          * Maps by Country
     * Int'l Codes
          * Country Codes
          * Int. Calling Codes
          * Currency Codes
          * Airport Codes


    Nations Online Logo 
    One World           
    Nations Online      

   Home Earth Continents Countries of the World Country Codes Country Codes
   List                                       

   related: List of Country Calling Codes     
             ___ Country Codes List                                           

   ISO Alpha-2, Alpha-3, and Numeric Country                                  
   Codes                                                                      

   The ISO country code are internationally                                   
   recognized codes that designates for each  
   country and most of the dependent areas a  
   two letter combination or a three letter   
   combination, its like an acronym, that     
   stands for a country.                      

   This code is used for example for the      
   two-letter suffixes such as .us (United    
   States), .fr (France) or .de (Germany) in  
   top-level domains (for countries) in the   Bookmark/share this page
   Internet.                                  IFrame
                                              Instagram
   The three letter code is also often used   
   at events with international participants  ____________________________
   from various countries like sports         [ Search ]
   meetings or song contests, where you can   
   see abbreviations like CAN (for Canada),   
   DNK (for Denmark), AUS (for Australia).    

   This is a list of two letter codes (ISO    
   alpha-2) and the three letter codes (ISO   
   alpha-3) as well as the United Nations     
   used numerical code M49 for countries,     
   dependencies, and other areas.             
   (Dependencies marked in Italic writing)    

   (To sort the data click on the respective  
   header of a column (to sort multiple       
   columns hold down the shift key while      
   selecting the columns to sort ).           


                                                               ISO Numeric    
       Country or Area Name           ISO "ALPHA-2 ISO ALPHA-3 Code           
                                      Code         Code        UN M49         
                                                               Numerical Code 
       Afghanistan                    AF           AFG         004            
   ALA Aland Islands                  AX           ALA         248            
       Albania                        AL           ALB         008            
       Algeria                        DZ           DZA         012            
       American Samoa                 AS           ASM         016            
       Andorra                        AD           AND         020            
       Angola                         AO           AGO         024            
       Anguilla                       AI           AIA         660            
       Antarctica                     AQ           ATA         010            
       Antigua and Barbuda            AG           ATG         028            
       Argentina                      AR           ARG         032            
       Armenia                        AM           ARM         051            
       Aruba                          AW           ABW         533            
       Australia                      AU           AUS         036            
       Austria                        AT           AUT         040            
       Azerbaijan                     AZ           AZE         031            
       Bahamas                        BS           BHS         044            
       Bahrain                        BH           BHR         048            
       Bangladesh                     BD           BGD         050            
       Barbados                       BB           BRB         052            
       Belarus                        BY           BLR         112            
       Belgium                        BE           BEL         056            
       Belize                         BZ           BLZ         084            
       Benin                          BJ           BEN         204            
       Bermuda                        BM           BMU         060            
       Bhutan                         BT           BTN         064            
       Bolivia                        BO           BOL         068            
       Bosnia and Herzegovina         BA           BIH         070            
       Botswana                       BW           BWA         072            
       Bouvet Island                  BV           BVT         074            
       Brazil                         BR           BRA         076            
       British Virgin Islands         VG           VGB         092            
       British Indian Ocean Territory IO           IOT         086            
       Brunei Darussalam              BN           BRN         096            
       Bulgaria                       BG           BGR         100            
       Burkina Faso                   BF           BFA         854            
       Burundi                        BI           BDI         108            
       Cambodia                       KH           KHM         116            
       Cameroon                       CM           CMR         120            
       Canada                         CA           CAN         124            
       Cape Verde                     CV           CPV         132            
       Cayman Islands                 KY           CYM         136            
       Central African Republic       CF           CAF         140            
       Chad                           TD           TCD         148            
       Chile                          CL           CHL         152            
       China                          CN           CHN         156            
       Hong Kong, Special             HK           HKG         344            
       Administrative Region of China                                         
       Macao, Special Administrative  MO           MAC         446            
       Region of China                                                        
       Christmas Island               CX           CXR         162            
       Cocos (Keeling) Islands        CC           CCK         166            
       Colombia                       CO           COL         170            
       Comoros                        KM           COM         174            
       Congo (Brazzaville)            CG           COG         178            
       Congo, Democratic Republic of  CD           COD         180            
       the                                                                    
       Cook Islands                   CK           COK         184            
       Costa Rica                     CR           CRI         188            
       C\F4te d'Ivoire                  CI           CIV         384            
       Croatia                        HR           HRV         191            
       Cuba                           CU           CUB         192            
       Cyprus                         CY           CYP         196            
       Czech Republic                 CZ           CZE         203            
       Denmark                        DK           DNK         208            
       Djibouti                       DJ           DJI         262            
       Dominica                       DM           DMA         212            
       Dominican Republic             DO           DOM         214            
       Ecuador                        EC           ECU         218            
       Egypt                          EG           EGY         818            
       El Salvador                    SV           SLV         222            
       Equatorial Guinea              GQ           GNQ         226            
       Eritrea                        ER           ERI         232            
       Estonia                        EE           EST         233            
       Ethiopia                       ET           ETH         231            
       Falkland Islands (Malvinas)    FK           FLK         238            
       Faroe Islands                  FO           FRO         234            
       Fiji                           FJ           FJI         242            
       Finland                        FI           FIN         246            
       France                         FR           FRA         250            
       French Guiana                  GF           GUF         254            
       French Polynesia               PF           PYF         258            
       French Southern Territories    TF           ATF         260            
       Gabon                          GA           GAB         266            
       Gambia                         GM           GMB         270            
       Georgia                        GE           GEO         268            
       Germany                        DE           DEU         276            
       Ghana                          GH           GHA         288            
       Gibraltar                      GI           GIB         292            
       Greece                         GR           GRC         300            
       Greenland                      GL           GRL         304            
       Grenada                        Gd           GRD         308            
       Guadeloupe                     GP           GLP         312            
       Guam                           GU           GUM         316            
       Guatemala                      GT           GTM         320            
       Guernsey                       GG           GGY         831            
       Guinea                         GN           GIN         324            
       Guinea-Bissau                  GW           GNB         624            
       Guyana                         GY           GUY         328            
       Haiti                          HT           HTI         332            
       Heard Island and Mcdonald      HM           HMD         334            
       Islands                                                                
       Holy See (Vatican City State)  VA           VAT         336            
       Honduras                       HN           HND         340            
       Hungary                        HU           HUN         348            
       Iceland                        IS           ISL         352            
       India                          IN           IND         356            
       Indonesia                      ID           IDN         360            
       Iran, Islamic Republic of      IR           IRN         364            
       Iraq                           IQ           IRQ         368            
       Ireland                        IE           IRL         372            
       Isle of Man                    IM           IMN         833            
       Israel                         IL           ISR         376            
       Italy                          IT           ITA         380            
       Jamaica                        JM           JAM         388            
       Japan                          JP           JPN         392            
       Jersey                         JE           JEY         832            
       Jordan                         JO           JOR         400            
       Kazakhstan                     KZ           KAZ         398            
       Kenya                          KE           KEN         404            
       Kiribati                       KI           KIR         296            
       Korea, Democratic People's     KP           PRK         408            
       Republic of                                                            
       Korea, Republic of             KR           KOR         410            
       Kuwait                         KW           KWT         414            
       Kyrgyzstan                     KG           KGZ         417            
       Lao PDR                        LA           LAO         418            
       Latvia                         LV           LVA         428            
       Lebanon                        LB           LBN         422            
       Lesotho                        LS           LSO         426            
       Liberia                        LR           LBR         430            
       Libya                          LY           LBY         434            
       Liechtenstein                  LI           LIE         438            
       Lithuania                      LT           LTU         440            
       Luxembourg                     LU           Lux         442            
       Macedonia, Republic of         MK           MKD         807            
       Madagascar                     MG           MDG         450            
       Malawi                         MW           MWI         454            
       Malaysia                       MY           MYS         458            
       Maldives                       MV           MDV         462            
       Mali                           ML           MLI         466            
       Malta                          MT           MLT         470            
       Marshall Islands               MH           MHL         584            
       Martinique                     MQ           MTQ         474            
       Mauritania                     MR           MRT         478            
       Mauritius                      MU           MUS         480            
       Mayotte                        YT           MYT         175            
       Mexico                         MX           MEX         484            
       Micronesia, Federated States   FM           FSM         583            
       of                                                                     
       Moldova                        MD           MDA         498            
       Monaco                         MC           MCO         492            
       Mongolia                       MN           MNG         496            
       Montenegro                     ME           MNE         499            
       Montserrat                     MS           MSR         500            
       Morocco                        MA           MAR         504            
       Mozambique                     MZ           MOZ         508            
       Myanmar                        MM           MMR         104            
       Namibia                        NA           NAM         516            
       Nauru                          NR           NRU         520            
       Nepal                          NP           NPL         524            
       Netherlands                    NL           NLD         528            
       Netherlands Antilles           AN           ANT         530            
       New Caledonia                  NC           NCL         540            
       New Zealand                    NZ           NZL         554            
       Nicaragua                      NI           NIC         558            
       Niger                          NE           NER         562            
       Nigeria                        NG           NGA         566            
       Niue                           NU           NIU         570            
       Norfolk Island                 NF           NFK         574            
       Northern Mariana Islands       MP           MNP         580            
       Norway                         NO           NOR         578            
       Oman                           OM           OMN         512            
       Pakistan                       PK           PAK         586            
       Palau                          PW           PLW         585            
       Palestinian Territory,         PS           PSE         275            
       Occupied                                                               
       Panama                         PA           PAN         591            
       Papua New Guinea               PG           PNG         598            
       Paraguay                       PY           PRY         600            
       Peru                           PE           PER         604            
       Philippines                    PH           PHL         608            
       Pitcairn                       PN           PCN         612            
       Poland                         PL           POL         616            
       Portugal                       PT           PRT         620            
       Puerto Rico                    PR           PRI         630            
       Qatar                          QA           QAT         634            
       R\E9union                        RE           REU         638            
       Romania                        RO           ROU         642            
       Russian Federation             RU           RUS         643            
       Rwanda                         RW           RWA         646            
       Saint-Barth\E9lemy               BL           BLM         652            
       Saint Helena                   SH           SHN         654            
       Saint Kitts and Nevis          KN           KNA         659            
       Saint Lucia                    LC           LCA         662            
       Saint-Martin (French part)     MF           MAF         663            
       Saint Pierre and Miquelon      PM           SPM         666            
       Saint Vincent and Grenadines   VC           VCT         670            
       Samoa                          WS           WSM         882            
       San Marino                     SM           SMR         674            
       Sao Tome and Principe          ST           STP         678            
       Saudi Arabia                   SA           SAU         682            
       Senegal                        SN           SEN         686            
       Serbia                         RS           SRB         688            
       Seychelles                     SC           SYC         690            
       Sierra Leone                   SL           SLE         694            
       Singapore                      SG           SGP         702            
       Slovakia                       SK           SVK         703            
       Slovenia                       SI           SVN         705            
       Solomon Islands                SB           SLB         090            
       Somalia                        SO           SOM         706            
       South Africa                   ZA           ZAF         710            
       South Georgia and the South    GS           SGS         239            
       Sandwich Islands                                                       
       South Sudan                    SS           SSD         728            
       Spain                          ES           ESP         724            
       Sri Lanka                      LK           LKA         144            
       Sudan                          SD           SDN         736            
       Suriname *                     SR           SUR         740            
       Svalbard and Jan Mayen Islands SJ           SJM         744            
       Swaziland                      SZ           SWZ         748            
       Sweden                         SE           SWE         752            
       Switzerland                    CH           CHE         756            
       Syrian Arab Republic (Syria)   SY           SYR         760            
       Taiwan, Republic of China      TW           TWN         158            
       Tajikistan                     TJ           TJK         762            
       Tanzania *, United Republic of TZ           TZA         834            
       Thailand                       TH           THA         764            
       Timor-Leste                    TL           TLS         626            
       Togo                           TG           TGO         768            
       Tokelau                        TK           TKL         772            
       Tonga                          TO           TON         776            
       Trinidad and Tobago            TT           TTO         780            
       Tunisia                        TN           TUN         788            
       Turkey                         TR           TUR         792            
       Turkmenistan                   TM           TKM         795            
       Turks and Caicos Islands       TC           TCA         796            
       Tuvalu                         TV           TUV         798            
       Uganda                         UG           UGA         800            
       Ukraine                        UA           UKR         804            
       United Arab Emirates           AE           ARE         784            
       United Kingdom                 GB           GBR         826            
       United States of America       US           USA         840            
       United States Minor Outlying   UM           UMI         581            
       Islands                                                                
       Uruguay                        UY           URY         858            
       Uzbekistan                     UZ           UZB         860            
       Vanuatu                        VU           VUT         548            
       Venezuela (Bolivarian Republic VE           VEN         862            
       of)                                                                    
       Viet Nam                       VN           VNM         704            
       Virgin Islands, US             VI           VIR         850            
       Wallis and Futuna Islands      WF           WLF         876            
       Western Sahara                 EH           ESH         732            
       Yemen                          YE           YEM         887            
       Zambia                         ZM           ZMB         894            
       Zimbabwe                       ZW           ZWE         716            

   [IMG] 


   Related Pages:                                        

   Country Dialing Codes   Related Consumer Information: 

   Airport Codes            

   Cities of the World   


   One World - Nations Online .:. let's care for this planet                  

   Actually, it's impossible to simulate freedom --- or?                      

   Nations Online Project is made to improve cross-cultural understanding and 
   global awareness.                                                          
   More signal - less NOISE                                                   

   Site Map | Information Sources | Disclaimer | Contact:                     
   [email protected] | Copyright \A9 1998-2016 :: nationsonline.org       


   up

Le code que j'ai essayé:

cat file | awk '{print $1,$2,$3}' > result

mais la sortie n'est pas propre car il y a des espaces blancs dans les 1ères colonnes, ainsi le contenu est perdu des colonnes suivantes

2
juggernauthk108

En utilisant la même idée de base que la réponse de @ Zanna, vous pouvez écrire un petit script awk qui définit une variable à 1 lorsque la 1ère ligne du tableau est trouvée et revient à 0 pour la dernière et imprimer toutes les lignes lues pendant le drapeau est un:

awk '/Country or/{a=1} a==1; /Zimbabwe/{a=0}' file

Le script ci-dessus définit la variable a sur 1 si la ligne actuelle correspond à Country or (le début du tableau) et le remet à 0 si la ligne actuelle correspond à Zimbabwe. L'action par défaut lorsque awk reçoit une expression qui prend la valeur true, consiste à imprimer la ligne. Par conséquent, a==1 seul entraîne la lecture de chaque ligne tandis que a est 1 à imprimer. C'est avant la vérification de Zimbabwe donc il peut aussi attraper la dernière ligne.

2
terdon

Comme apparemment, vous voulez juste la table entière et rien d'autre, vous pouvez simplement rechercher la première ligne et la dernière ligne que vous voulez ...

sed -n '/ISO Numeric/,/Zimbabwe/p' file
  • -n n'imprime rien tant que nous ne le demandons pas
  • /start/,/end/ recherche des lignes du début à la fin
  • p imprimer ces lignes
1
Zanna