Hi,
I have done a lot of regex in perl and feel like in no mans land in c++ :)
Well I want to parse a tab delimited file and want to print specific fields as per my needs. One more thing the input file may not be sorted and I want the final result to be sorted by first field.
Suppose file is like this:
1111<tab>2222<tab>A<tab>word1"jack"<tab>word2"chicago"
3333<tab>4444<tab>B<tab>word1"jack"<tab>word2"chicago"
5555<tab>6666<tab>C<tab>word1"jack"<tab>word2"chicago"
7777<tab>8888<tab>D<tab>word1"john"<tab>word2"london"
9999<tab>11000<tab>E<tab>word1"john"<tab>word2"london"
12000<tab>13000<tab>F<tab>word1"peter"<tab>word2"berlin"
14000<tab>15000<tab>G<tab>word1"peter"<tab>word2"berlin"
16000<tab>17000<tab>H<tab>word1"austin"<tab>word2"texus"
Now I don't want to use Boost. I have to parse a file in 1 GB - 5 GB max. I dont want this word1 and " stuff to be printed in the output file. Its very easy in perl but i donno about C++ howto.
Here is a very simple program I have written and I know it needs lots of modifications to do that kind of parsing.
From the above input here is how I want the output file to look like:-
1111<tab>jack<tab>chicago<tab>Start
3333<tab>jack<tab>chicago<tab>Middle
5555<tab>jack<tab>chicago<tab>End
7777<tab>john<tab>london<tab>Start
9999<tab>john<tab>london<tab>End
12000<tab>peter<tab>berlin<tab>Start
14000<tab>peter<tab>berlin<tab>End
16000<tab>austin<tab>texus<tab>Single
Here is my simple starting program:-
#include<iostream>
#include<fstream>
using namespace std;
int main() {
char buffer[256];
ifstream myfile("test.txt");
while(! myfile.eof()) {
myfile.getline(buffer, 100, '\t');
cout << buffer;
}
return 0;
}
Thanks :)