I've a small problem with text file in c++. I need to extract the value of one column with condition on the other one for example I have data file like below
I would greatly appreciate anyone's advice on how to print column 5 when column 1 = 3.310000. please note that the text file is might be under process from another function.
Should be straigt forward: Just read in the line, tokenize it, test for the first column, and do whatever you have to do when the first column is your desired value.
please note that the text file is might be under process from another function.
This means you have to put some if's for the case when the line is not long enough or contain strange half-values. And to put some catch clauses for IO-exceptions.
By the way: If you are not bound to C++, then doing this in some other language, especially scripting language would be much much easier. These kind of stuff is the reason people invented languages like perl or awk or even sed, but I guess most modern scripting languages will do the trick in like.. 4 lines of code.
Thanks Ciao for your reply.
Yes, you are right I'm not bound to C++. Actually, I know how to do that in awk command or perl language. but it has to be done in C++. I used the tokenize and everything is going fine except I can't print the specific column, only the whole line. I would appreciate if you can help out to print for example the column no. 2. here is my code.
By the way: If you are not bound to C++, then doing this in some other language, especially scripting language would be much much easier. These kind of stuff is the reason people invented languages like perl or awk or even sed, but I guess most modern scripting languages will do the trick in like.. 4 lines of code.
This would do the trick: $ grep ^3.310000 | cut -d' ' -f5
1
$