Program compiles, but no output is being generated - c++11

Essentially after running all of the below code, I'm aiming to output a single element of my Countries vector just to test and see if I'm actually populating it or not. Nothing is outputting though, no errors are met and If I screwed something up I have no clue how to go about fixing it.
#include <iostream>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <vector>
using namespace std;
struct Country {
string Name;
string Population;
string Area;
string Density;
string Migration;
string GDP;
string Literacy;
string Birthrate;
};
int main(){
ifstream data ("countries.csv");
vector<Country> Countries;
while (data.good()){
Country temp;
getline(data, temp.Name, ',');
getline(data, temp.Population, ',');
getline(data, temp.Area, ',');
getline(data, temp.Density, ',');
getline(data, temp.Migration, ',');
getline(data, temp.GDP, ',');
getline(data, temp.Literacy, ',');
getline(data, temp.Birthrate, '\n');
Countries.push_back(temp);
}
Country c1 = Countries[1];
Country c2 = Countries[2];
cout << c1.Name << ", " << c1.Population << ", " << c1.Area << ", "
<< c1.Density << ", " << c1.Migration << ", " << c1.GDP << ", "
<< c1.Literacy << ", " << c1.Birthrate << endl;
cout << c2.Name << ", " << c2.Population << ", " << c2.Area << ", "
<< c2.Density << ", " << c2.Migration << ", " << c2.GDP << ", "
<< c2.Literacy << ", " << c2.Birthrate << endl;
return 0;
}
This is the file in which I get the data
#Country,Population,Area (sq. mi.),Pop. Density (per sq. mi.),Net migration,GDP ($ per capita),Literacy (%),Birthrate
Afghanistan ,31056997,647500,48,23.06,700,36,46.6
Albania ,3581655,28748,124.6,-4.93,4500,86.5,15.11
Algeria ,32930091,2381740,13.8,-0.39,6000,70,17.14
American Samoa ,57794,199,290.4,-20.71,8000,97,22.46
Andorra ,71201,468,152.1,6.6,19000,100,8.71
Angola ,12127071,1246700,9.7,0,1900,42,45.11
Anguilla ,13477,102,132.1,10.76,8600,95,14.17
Antigua & Barbuda ,69108,443,156,-6.15,11000,89,16.93
Argentina ,39921833,2766890,14.4,0.61,11200,97.1,16.73
Armenia ,2976372,29800,99.9,-6.47,3500,98.6,12.07
Aruba ,71891,193,372.5,0,28000,97,11.03
Australia ,20264082,7686850,2.6,3.98,29000,100,12.14
Austria ,8192880,83870,97.7,2,30000,98,8.74
Azerbaijan ,7961619,86600,91.9,-4.9,3400,97,20.74
Bahamas. The ,303770,13940,21.8,-2.2,16700,95.6,17.57
Bahrain ,698585,665,1050.5,1.05,16900,89.1,17.8
Bangladesh ,147365352,144000,1023.4,-0.71,1900,43.1,29.8
Barbados ,279912,431,649.5,-0.31,15700,97.4,12.71
Belarus ,10293011,207600,49.6,2.54,6100,99.6,11.16
Belgium ,10379067,30528,340,1.23,29100,98,10.38
Belize ,287730,22966,12.5,0,4900,94.1,28.84
Benin ,7862944,112620,69.8,0,1100,40.9,38.85
Bermuda ,65773,53,1241,2.49,36000,98,11.4
Bhutan ,2279723,47000,48.5,0,1300,42.2,33.65
Bolivia ,8989046,1098580,8.2,-1.32,2400,87.2,23.3
Bosnia & Herzegovina ,4498976,51129,88,0.31,6100,,8.77
Botswana ,1639833,600370,2.7,0,9000,79.8,23.08
Brazil ,188078227,8511965,22.1,-0.03,7600,86.4,16.56
British Virgin Is. ,23098,153,151,10.01,16000,97.8,14.89
Brunei ,379444,5770,65.8,3.59,18600,93.9,18.79
Bulgaria ,7385367,110910,66.6,-4.58,7600,98.6,9.65
Burkina Faso ,13902972,274200,50.7,0,1100,26.6,45.62
Burma ,47382633,678500,69.8,-1.8,1800,85.3,17.91
Burundi ,8090068,27830,290.7,-0.06,600,51.6,42.22
Cambodia ,13881427,181040,76.7,0,1900,69.4,26.9
Cameroon ,17340702,475440,36.5,0,1800,79,33.89
Canada ,33098932,9984670,3.3,5.96,29800,97,10.78
Cape Verde ,420979,4033,104.4,-12.07,1400,76.6,24.87
Cayman Islands ,45436,262,173.4,18.75,35000,98,12.74
Central African Rep. ,4303356,622984,6.9,0,1100,51,33.91
Chad ,9944201,1284000,7.7,-0.11,1200,47.5,45.73
Chile ,16134219,756950,21.3,0,9900,96.2,15.23
China ,1313973713,9596960,136.9,-0.4,5000,90.9,13.25
Colombia ,43593035,1138910,38.3,-0.31,6300,92.5,20.48
Comoros ,690948,2170,318.4,0,700,56.5,36.93
Congo. Dem. Rep. ,62660551,2345410,26.7,0,700,65.5,43.69
Congo. Repub. of the ,3702314,342000,10.8,-0.17,700,83.8,42.57
Cook Islands ,21388,240,89.1,,5000,95,21
Costa Rica ,4075261,51100,79.8,0.51,9100,96,18.32
Cote d'Ivoire ,17654843,322460,54.8,-0.07,1400,50.9,35.11
Croatia ,4494749,56542,79.5,1.58,10600,98.5,9.61
Cuba ,11382820,110860,102.7,-1.58,2900,97,11.89
Cyprus ,784301,9250,84.8,0.43,19200,97.6,12.56
Czech Republic ,10235455,78866,129.8,0.97,15700,99.9,9.02
Denmark ,5450661,43094,126.5,2.48,31100,100,11.13
Djibouti ,486530,23000,21.2,0,1300,67.9,39.53
Dominica ,68910,754,91.4,-13.87,5400,94,15.27
Dominican Republic ,9183984,48730,188.5,-3.22,6000,84.7,23.22
East Timor ,1062777,15007,70.8,0,500,58.6,26.99
Ecuador ,13547510,283560,47.8,-8.58,3300,92.5,22.29
Egypt ,78887007,1001450,78.8,-0.22,4000,57.7,22.94
El Salvador ,6822378,21040,324.3,-3.74,4800,80.2,26.61
Equatorial Guinea ,540109,28051,19.3,0,2700,85.7,35.59
Eritrea ,4786994,121320,39.5,0,700,58.6,34.33
Estonia ,1324333,45226,29.3,-3.16,12300,99.8,10.04
Ethiopia ,74777981,1127127,66.3,0,700,42.7,37.98
Faroe Islands ,47246,1399,33.8,1.41,22000,,14.05
Fiji ,905949,18270,49.6,-3.14,5800,93.7,22.55
Finland ,5231372,338145,15.5,0.95,27400,100,10.45
France ,60876136,547030,111.3,0.66,27600,99,11.99
French Guiana ,199509,91000,2.2,6.27,8300,83,20.46
French Polynesia ,274578,4167,65.9,2.94,17500,98,16.68
Gabon ,1424906,267667,5.3,0,5500,63.2,36.16
Gambia. The ,1641564,11300,145.3,1.57,1700,40.1,39.37
Gaza Strip ,1428757,360,3968.8,1.6,600,,39.45
Georgia ,4661473,69700,66.9,-4.7,2500,99,10.41
Germany ,82422299,357021,230.9,2.18,27600,99,8.25
Ghana ,22409572,239460,93.6,-0.64,2200,74.8,30.52
Gibraltar ,27928,7,3989.7,0,17500,,10.74
Greece ,10688058,131940,81,2.35,20000,97.5,9.68
Greenland ,56361,2166086,0,-8.37,20000,,15.93
Grenada ,89703,344,260.8,-13.92,5000,98,22.08
Guadeloupe ,452776,1780,254.4,-0.15,8000,90,15.05
Guam ,171019,541,316.1,0,21000,99,18.79
Guatemala ,12293545,108890,112.9,-1.67,4100,70.6,29.88
Guernsey ,65409,78,838.6,3.84,20000,,8.81
Guinea ,9690222,245857,39.4,-3.06,2100,35.9,41.76
Guinea-Bissau ,1442029,36120,39.9,-1.57,800,42.4,37.22
Guyana ,767245,214970,3.6,-2.07,4000,98.8,18.28
Haiti ,8308504,27750,299.4,-3.4,1600,52.9,36.44
Honduras ,7326496,112090,65.4,-1.99,2600,76.2,28.24
Hong Kong ,6940432,1092,6355.7,5.24,28800,93.5,7.29
Hungary ,9981334,93030,107.3,0.86,13900,99.4,9.72
Iceland ,299388,103000,2.9,2.38,30900,99.9,13.64
India ,1095351995,3287590,333.2,-0.07,2900,59.5,22.01
Indonesia ,245452739,1919440,127.9,0,3200,87.9,20.34
Iran ,68688433,1648000,41.7,-0.84,7000,79.4,17
Iraq ,26783383,437072,61.3,0,1500,40.4,31.98
Ireland ,4062235,70280,57.8,4.99,29600,98,14.45
Isle of Man ,75441,572,131.9,5.36,21000,,11.05
Israel ,6352117,20770,305.8,0.68,19800,95.4,17.97
Italy ,58133509,301230,193,2.07,26700,98.6,8.72
Jamaica ,2758124,10991,250.9,-4.92,3900,87.9,20.82
Japan ,127463611,377835,337.4,0,28200,99,9.37
Jersey ,91084,116,785.2,2.76,24800,,9.3
Jordan ,5906760,92300,64,6.59,4300,91.3,21.25
Kazakhstan ,15233244,2717300,5.6,-3.35,6300,98.4,16
Kenya ,34707817,582650,59.6,-0.1,1000,85.1,39.72
Kiribati ,105432,811,130,0,800,,30.65
Korea. North ,23113019,120540,191.8,0,1300,99,15.54
Korea. South ,48846823,98480,496,0,17800,97.9,10
Kuwait ,2418393,17820,135.7,14.18,19000,83.5,21.94
Kyrgyzstan ,5213898,198500,26.3,-2.45,1600,97,22.8
Laos ,6368481,236800,26.9,0,1700,66.4,35.49
Latvia ,2274735,64589,35.2,-2.23,10200,99.8,9.24
Lebanon ,3874050,10400,372.5,0,4800,87.4,18.52
Lesotho ,2022331,30355,66.6,-0.74,3000,84.8,24.75
Liberia ,3042004,111370,27.3,0,1000,57.5,44.77
Libya ,5900754,1759540,3.4,0,6400,82.6,26.49
Liechtenstein ,33987,160,212.4,4.85,25000,100,10.21
Lithuania ,3585906,65200,55,-0.71,11400,99.6,8.75
Luxembourg ,474413,2586,183.5,8.97,55100,100,11.94
Macau ,453125,28,16183,4.86,19400,94.5,8.48
Macedonia ,2050554,25333,80.9,-1.45,6700,,12.02
Madagascar ,18595469,587040,31.7,0,800,68.9,41.41
Malawi ,13013926,118480,109.8,0,600,62.7,43.13
Malaysia ,24385858,329750,74,0,9000,88.7,22.86
Maldives ,359008,300,1196.7,0,3900,97.2,34.81
Mali ,11716829,1240000,9.5,-0.33,900,46.4,49.82
Malta ,400214,316,1266.5,2.07,17700,92.8,10.22
Marshall Islands ,60422,11854,5.1,-6.04,1600,93.7,33.05
Martinique ,436131,1100,396.5,-0.05,14400,97.7,13.74
Mauritania ,3177388,1030700,3.1,0,1800,41.7,40.99
Mauritius ,1240827,2040,608.3,-0.9,11400,85.6,15.43
Mayotte ,201234,374,538.1,6.78,2600,,40.95
Mexico ,107449525,1972550,54.5,-4.87,9000,92.2,20.69
Micronesia. Fed. St. ,108004,702,153.9,-20.99,2000,89,24.68
Moldova ,4466706,33843,132,-0.26,1800,99.1,15.7
Monaco ,32543,2,16271.5,7.75,27000,99,9.19
Mongolia ,2832224,1564116,1.8,0,1800,97.8,21.59
Montserrat ,9439,102,92.5,0,3400,97,17.59
Morocco ,33241259,446550,74.4,-0.98,4000,51.7,21.98
Mozambique ,19686505,801590,24.6,0,1200,47.8,35.18
Namibia ,2044147,825418,2.5,0,7200,84,24.32
Nauru ,13287,21,632.7,0,5000,,24.76
Nepal ,28287147,147181,192.2,0,1400,45.2,30.98
Netherlands ,16491461,41526,397.1,2.91,28600,99,10.9
Netherlands Antilles ,221736,960,231,-0.41,11400,96.7,14.78
New Caledonia ,219246,19060,11.5,0,15000,91,18.11
New Zealand ,4076140,268680,15.2,4.05,21600,99,13.76
Nicaragua ,5570129,129494,43,-1.22,2300,67.5,24.51
Niger ,12525094,1267000,9.9,-0.67,800,17.6,50.73
Nigeria ,131859731,923768,142.7,0.26,900,68,40.43
N. Mariana Islands ,82459,477,172.9,9.61,12500,97,19.43
Norway ,4610820,323802,14.2,1.74,37800,100,11.46
Oman ,3102229,212460,14.6,0.28,13100,75.8,36.24
Pakistan ,165803560,803940,206.2,-2.77,2100,45.7,29.74
Palau ,20579,458,44.9,2.85,9000,92,18.03
Panama ,3191319,78200,40.8,-0.91,6300,92.6,21.74
Papua New Guinea ,5670544,462840,12.3,0,2200,64.6,29.36
Paraguay ,6506464,406750,16,-0.08,4700,94,29.1
Peru ,28302603,1285220,22,-1.05,5100,90.9,20.48
Philippines ,89468677,300000,298.2,-1.5,4600,92.6,24.89
Poland ,38536869,312685,123.3,-0.49,11100,99.8,9.85
Portugal ,10605870,92391,114.8,3.57,18000,93.3,10.72
Puerto Rico ,3927188,13790,284.8,-1.46,16800,94.1,12.77
Qatar ,885359,11437,77.4,16.29,21500,82.5,15.56
Reunion ,787584,2517,312.9,0,5800,88.9,18.9
Romania ,22303552,237500,93.9,-0.13,7000,98.4,10.7
Russia ,142893540,17075200,8.4,1.02,8900,99.6,9.95
Rwanda ,8648248,26338,328.4,0,1300,70.4,40.37
Saint Helena ,7502,413,18.2,0,2500,97,12.13
Saint Kitts & Nevis ,39129,261,149.9,-7.11,8800,97,18.02
Saint Lucia ,168458,616,273.5,-2.67,5400,67,19.68
St Pierre & Miquelon ,7026,242,29,-4.86,6900,99,13.52
St Vincent & Grenadines ,117848,389,303,-7.64,2900,96,16.18
Samoa ,176908,2944,60.1,-11.7,5600,99.7,16.43
San Marino ,29251,61,479.5,10.98,34600,96,10.02
Sao Tome & Principe ,193413,1001,193.2,-2.72,1200,79.3,40.25
Saudi Arabia ,27019731,1960582,13.8,-2.71,11800,78.8,29.34
Senegal ,11987121,196190,61.1,0.2,1600,40.2,32.78
Serbia ,9396411,88361,106.3,-1.33,2200,93,
Seychelles ,81541,455,179.2,-5.69,7800,58,16.03
Sierra Leone ,6005250,71740,83.7,0,500,31.4,45.76
Singapore ,4492150,693,6482.2,11.53,23700,92.5,9.34
Slovakia ,5439448,48845,111.4,0.3,13300,,10.65
Slovenia ,2010347,20273,99.2,1.12,19000,99.7,8.98
Solomon Islands ,552438,28450,19.4,0,1700,,30.01
Somalia ,8863338,637657,13.9,5.37,500,37.8,45.13
South Africa ,44187637,1219912,36.2,-0.29,10700,86.4,18.2
Spain ,40397842,504782,80,0.99,22000,97.9,10.06
Sri Lanka ,20222240,65610,308.2,-1.31,3700,92.3,15.51
Sudan ,41236378,2505810,16.5,-0.02,1900,61.1,34.53
Suriname ,439117,163270,2.7,-8.81,4000,93,18.02
Swaziland ,1136334,17363,65.5,0,4900,81.6,27.41
Sweden ,9016596,449964,20,1.67,26800,99,10.27
Switzerland ,7523934,41290,182.2,4.05,32700,99,9.71
Syria ,18881361,185180,102,0,3300,76.9,27.76
Taiwan ,23036087,35980,640.3,0,23400,96.1,12.56
Tajikistan ,7320815,143100,51.2,-2.86,1000,99.4,32.65
Tanzania ,37445392,945087,39.6,-2.06,600,78.2,37.71
Thailand ,64631595,514000,125.7,0,7400,92.6,13.87
Togo ,5548702,56785,97.7,0,1500,60.9,37.01
Tonga ,114689,748,153.3,0,2200,98.5,25.37
Trinidad & Tobago ,1065842,5128,207.9,-10.83,9500,98.6,12.9
Tunisia ,10175014,163610,62.2,-0.57,6900,74.2,15.52
Turkey ,70413958,780580,90.2,0,6700,86.5,16.62
Turkmenistan ,5042920,488100,10.3,-0.86,5800,98,27.61
Turks & Caicos Is ,21152,430,49.2,11.68,9600,98,21.84
Tuvalu ,11810,26,454.2,0,1100,,22.18
Uganda ,28195754,236040,119.5,0,1400,69.9,47.35
Ukraine ,46710816,603700,77.4,-0.39,5400,99.7,8.82
United Arab Emirates ,2602713,82880,31.4,1.03,23200,77.9,18.96
United Kingdom ,60609153,244820,247.6,2.19,27700,99,10.71
United States ,298444215,9631420,31,3.41,37800,97,14.14
Uruguay ,3431932,176220,19.5,-0.32,12800,98,13.91
Uzbekistan ,27307134,447400,61,-1.72,1700,99.3,26.36
Vanuatu ,208869,12200,17.1,0,2900,53,22.72
Venezuela ,25730435,912050,28.2,-0.04,4800,93.4,18.71
Vietnam ,84402966,329560,256.1,-0.45,2500,90.3,16.86
Virgin Islands ,108605,1910,56.9,-8.94,17200,,13.96
Wallis and Futuna ,16025,274,58.5,,3700,50,
West Bank ,2460492,5860,419.9,2.98,800,,31.67
Western Sahara ,273008,266000,1,,,,
Yemen ,21456188,527970,40.6,0,800,50.2,42.89
Zambia ,11502010,752614,15.3,0,800,80.6,41
Zimbabwe ,12236805,390580,31.3,0,1900,90.7,28.01

Related

When I click the mouse how do I make it so the arrays re shuffle and have a different output?

The goal of the project is to make a MadLib. I want the array to shuffle each time the mouse is clicked, how would I go about doing that?
String madLib = "I went to #place# with #person#. I know #person# from when we #event#. At #place# we saw #thing#. It was #adjective# so we ran away to #otherPlace#. ";
String[] array1 = {"Pakistan", "The Pentagon", "Universal Studios Sound Stage No. 5", "The basement of the United States Embassy in Iran", "Uncle Randy's Attic"};
String[] array2 = {"Former President Bill Clinton", "Ten Dolla Founding Fatha Alexander Hamilton", "Former Bufffalo Bills Running Back Orenthal James 'OJ' Simpson ", "Clifford From Clifford The Big Red Dog", "Director and 2 time oscar winner Quentin Tarantino "};
String[] array3 = {"Stole the entire contents of Fort Knox", "Taught John D. Rockefeller how to get oil", "Tried to but failed to prevent the Cold War", "Tried to save Brandon Lee", "Attemted to rob a Boost Mobile and got locked in"};
String[] array4 = {"A taxidermied lion with three legs ", "cryogenically frozen Walt Disney", "A below average height but above average speed brown colored horse", "A bucket of warm cow milk", "A replica of political podcaster Ben Shapiro"};
String[] array5 = {"Barking", "Running around", "Eating the Travis Scott meal from McDonalds", "Watching Season 1 of Mickeymouse Clubhouse", "Verbally abusing a cardboard cutout of Air Buddy for the Air Bud movies"};
String[] array6 = {"A random house", "the museum of cats", "The dog adoption center", "The Wendys drivethrough line", "The window and light fixture store"};
void setup() {
}
void draw(){
}
void mousePressed(){
int index1 = int(random(array1.length));
int index2 = int(random(array2.length));
int index3 = int(random(array3.length));
int index4 = int(random(array4.length));
int index5 = int(random(array5.length));
int index6 = int(random(array6.length));
madLib = madLib.replace("#place#", (array1[index1]));
madLib = madLib.replace("#person#", (array2[index2]));
madLib = madLib.replace("#event#", (array3[index3]));
madLib = madLib.replace("#thing#", (array4[index4]));
madLib = madLib.replace("#adjective#", (array5[index5]));
madLib = madLib.replace("#otherPlace#", (array6[index6]));
println(madLib);
}
What you have written in mousePressed modifies the original madLib string, replacing all the hash delimited parameters with new information. That works fine the first time it is run and the string that is printed has those parameters replaced so you get the right output.
But now the madLib string doesn't contain any hash delimited parameters, so when mousePressed runs again none of the replace commands does anything because the hash delimited parameters they are replacing no longer exist.
So you need to modify a copy of the string and do your replacements on the copy and leave the original string alone. Thanks to #GeorgeProfenza for this code sample:
String madLib = "I went to #place# with #person#. I know #person# from when we #event#. At #place# we saw #thing#. It was #adjective# so we ran away to #otherPlace#. ";
String[] array1 = {"Pakistan", "The Pentagon", "Universal Studios Sound Stage No. 5", "The basement of the United States Embassy in Iran", "Uncle Randy's Attic"};
String[] array2 = {"Former President Bill Clinton", "Ten Dolla Founding Fatha Alexander Hamilton", "Former Bufffalo Bills Running Back Orenthal James 'OJ' Simpson ", "Clifford From Clifford The Big Red Dog", "Director and 2 time oscar winner Quentin Tarantino "};
String[] array3 = {"Stole the entire contents of Fort Knox", "Taught John D. Rockefeller how to get oil", "Tried to but failed to prevent the Cold War", "Tried to save Brandon Lee", "Attemted to rob a Boost Mobile and got locked in"};
String[] array4 = {"A taxidermied lion with three legs ", "cryogenically frozen Walt Disney", "A below average height but above average speed brown colored horse", "A bucket of warm cow milk", "A replica of political podcaster Ben Shapiro"};
String[] array5 = {"Barking", "Running around", "Eating the Travis Scott meal from McDonalds", "Watching Season 1 of Mickeymouse Clubhouse", "Verbally abusing a cardboard cutout of Air Buddy for the Air Bud movies"};
String[] array6 = {"A random house", "the museum of cats", "The dog adoption center", "The Wendys drivethrough line", "The window and light fixture store"};
void setup() {
}
void draw() {
}
void mousePressed() {
int index1 = int(random(array1.length));
int index2 = int(random(array2.length));
int index3 = int(random(array3.length));
int index4 = int(random(array4.length));
int index5 = int(random(array5.length));
int index6 = int(random(array6.length));
String madLibResult = madLib.replace("#place#", (array1[index1]));
madLibResult = madLibResult.replace("#person#", (array2[index2]));
madLibResult = madLibResult.replace("#event#", (array3[index3]));
madLibResult = madLibResult.replace("#thing#", (array4[index4]));
madLibResult = madLibResult.replace("#adjective#", (array5[index5]));
madLibResult = madLibResult.replace("#otherPlace#", (array6[index6]));
println(madLibResult);
}

Comparison between two tab separated files in unix using awk

I've written this code on unix but I am facing the problem as mentioned below.
My Code is:
paste 1.txt 2.txt|
awk ' { FS = "\t " } ; NR == 1 { n = NF/2 }
{for(i=1;i<=n;i++)
if($i!=$(i+n))
{c = c s i; s = "," }
if(c)
{print "Line No. " NR-1 " COLUMN NO " c;
c = "" ; s = "" } } '
Expected Output:
Line No. 2 COLUMN NO 2,3
Line No. 4 COLUMN NO 1,2,3,4
Line No. 6 COLUMN NO 2,3,4,5
Line No. 7 COLUMN NO 1,2,3,4,5
Output that is getting generated:
Line No. 2 COLUMN NO 2,3
Line No. 4 COLUMN NO 1,2,3,4
Line No. 6 COLUMN NO 2,3,4,5
Line No. 7 COLUMN NO 1,2,3,4
Below specified file is space separated. To understand it better I have formatted it this way.
File1:
ID_ID First_name Last_name Address Contact_Number
ID1 John Rock 32, Park Lake, California 2222200000
ID2 Tommy Hill 5322 Otter Lane Middleberge 3333300000
ID3 Leonardo Test Half-Way Pond, Georgetown 4444400000
ID8 Rhyan Bigsh 6762,33 Ave N,St. Petersburg 5555500000
ID50 Steve Goldberg 6762,33 Ave N,St. Petersburg 6666600000
ID60 Steve Goldberg 6666600000
File2:
ID_ID First_name Last_name Address Contact_Number
ID1 John Rock 32, Park Lake, California 2222200000
ID2 Tommy1 Hill1 5322 Otter Lane Middleberge 3333300000
ID3 Leonardo Test Half-Way Pond, Georgetown 4444400000
ID80 Sylvester Stallone 5555500000
ID50 Steve Goldberg 6762,33 Ave N,St. Petersburg 6666600000
ID60 Mark Waugh St. Petersburg 7777700000
ID70 John Smith 8888800000

Ruby code to extract data from irregular text with intelligence

I am trying to write a ruby code to extract data from specific location from irregular text content.
The following is the text content something I am looking at.
Address1 Address2
adress1, adress1, # 34 , adress1,
4th Floor, Plot # 14 & 15,
Drive,, HARIKA BHIMANI
Madhapur, Hyderabad - 500081 2-14-117/35-1 Nas
Andhra Pradesh AP
+(91)40-00000000
xyz#dabc.com
This is my weird text and I want to extract Address1 and Address2 separately.
I thought I will try split but did not get how to extract Address1 and Address2 separately since both of them are in the single line. The space between content of Address1 and Address2 will be more than 2 space for sure.
I am planning to parse each line and split string in each line with separator more than 1 space. How do split the string in ruby with separator character more than two space ?
We can ignore the first 2 lines in the above text and start from 3rd line. Basically I want to separate out left side and right side data. The separator is more than 2 spaces. I have edited the question with my sample coding but it is failing if one of the line in the left side data is empty
I have tried following sample
if !line.empty?
splits = line.split(/ {2,}/)
case splits.length
when 2
puts "Address1 "+ splits[1]
when 3
puts "Address1 "+ splits[1]
puts "Address2 "+ splits[2]
else
end
end
But it fails for the following sample
leftSideHasData rightSideHasData
OnlyRightSideHasData
How can I achieve this in Ruby ? Does ruby provide any apis to do this with ease ?
text = %W{ Address1 Address2
adress1, adress1, # 34 , adress1,
4th Floor, Plot # 14 & 15,
Drive,, HARIKA BHIMANI
Madhapur, Hyderabad - 500081 2-14-117/35-1 Nas
Andhra Pradesh AP
+(91)40-00000000
xyz#dabc.com}
rows = text.split("\n").map { |row| row.split(/\s{2,}/) }
rows.each { |row| address1 << row[0]; address2 << row[1] }
address1
=> ["",
" adress1, adress1, # 34 , adress1, ",
" 4th Floor, Plot # 14 & 15, ",
" Drive,,",
" Madhapur, Hyderabad - 500081",
" Andhra Pradesh",
" +(91)40-00000000",
" xyz#dabc.com"]
address2
=> ["Address1", nil, nil, "HARIKA BHIMANI", "2-14-117/35-1 Nas", "AP", nil, nil]
You can remove nils with address2.compact

interval map in C++

I need to map some intervals (actually these are intervals of addresses) to object ids.
I tried to use boost's interval_map, the example looks very pretty, it easily enumerates all intervals like:
while(it != party.end())
{
interval<ptime>::type when = it->first;
// Who is at the party within the time interval 'when' ?
GuestSetT who = (*it++).second;
cout << when << ": " << who << endl;
}
Which outputs:
----- History of party guests -------------------------
[2008-May-20 19:30:00, 2008-May-20 20:10:00): Harry Mary
[2008-May-20 20:10:00, 2008-May-20 22:15:00): Diana Harry Mary Susan
[2008-May-20 22:15:00, 2008-May-20 23:00:00): Diana Harry Mary Peter Susan
[2008-May-20 23:00:00, 2008-May-21 00:00:00): Diana Peter Susan
[2008-May-21 00:00:00, 2008-May-21 00:30:00): Peter
but it cannot do something like this:
interval<ptime>::type when =
interval<ptime>::closed(
time_from_string("2008-05-20 22:00"),
time_from_string("2008-05-20 22:01"));
GuestSetT who = party[when];
cout << when << ": " << who << endl;
it outputs: error: no match for 'operator[]' in 'party[when]'
it looks strange, since the main function of map is in operator[]
so I cannot get information "who were at the party at a given time"
Is there a ready-to-use solution for this problem?
It's somewhat counter-intuitive, but the () operator is what you're looking for. From the docs, operator() is defined as "Return[ing] the mapped value for a key x. The operator is only available for total maps."
Source: http://www.boost.org/doc/libs/1_54_0/libs/icl/doc/html/boost_icl/function_reference/selection.html

split text file VBS and give column headers

Parse the name field as "Last Name", First Name, Middle. If there is a second name then the second name needs to be in its own field. Not all names have a second name.
If the name is a business I would need the entire name in the last name field and a blank in the first and middle names.
My code:
Const ForReading = 1
x=0
on error resume next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("Test.txt", ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
arrName = Split(strLine, vbTab)
msgbox(arrName(x))
x = x+1
Loop
file looks as follows
Name 2nd name
ABDELMAGID A SMITH & LISA S
ABDELMAGID A SMITH & LISA S
CLEVELAND SANDY LEE
CLEVELAND SANDY LEE
WHALEN STEPHEN H & JOAN L
WHALEN STEPHEN H & JOAN L
BANK TWO OF VIRGINIA INC C/O DOE JOHN
BANK TWO OF VIRGINIA INC C/O DOE JOHN
BANK TWO OF VIRGINIA INC C/O DOE JOHN
SMITH JOHN ELLIS JR
JONES JOHN III

Resources