Some garbage code (without error checking, for simplicity):
Code:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
int main() {
FILE* in = fopen("input", "r");
FILE* out = fopen("output", "w");
std::set<std::string> lookup;
std::vector<std::string> lines;
char buffer[256];
while(fgets(buffer, 256, in) != NULL) {
char* timestamp = strrchr(buffer, ';');
std::string str(timestamp);
if(lookup.find(str) == lookup.end()) {
lookup.insert(str);
lines.push_back(buffer);
}
}
// Sort and output.
std::sort(lines.begin(), lines.end());
for(auto line : lines)
{
fputs(line.c_str(), out);
}
fclose(in);
fclose(out);
return 0;
}
The idea is: keep a set of unique timestamps, add lines without a duplicate timestamp to a vector for sorting. I make many assumptions; importantly, the input format shall be consistent, and the final character in the input file shall be a newline. You should adapt this code to fit your requirements.