cat data | sort -k1,2 |uniq -c >some-fileHowever, this might take hours to finish. While using the following C++ codes can finishes them in just a few minutes.
Then,#include <iostream> #include <string> #include <map> class rcd { public: std::string scf; int bp; rcd(std::string s, int b):scf{s}, bp{b}{}; }; bool operator<(const rcd&a, const rcd&b) { return (a.scf==b.scf)?a.bp<b.bp:a.scf<b.scf; } using namespace std; int main(int argc, char *argv[]) { map<rcd,int> pos; string ts; int t; while(cin>>ts>>t) ++pos[rcd(ts,t)]; clog<<pos.size()<<endl; for(auto t=pos.begin(); t!=pos.end(); ++t) cout<<t->first.scf<<' '<<t->first.bp<<' '<<t->second<<'\n'; return 0; }
g++ -std=c++11 sort.cppThis program will sort the data and count to data.new and put overall unique record number to standard out.
cat data | ./a.out > data.new
By modifying number of fields and corresponding comparison operator, sorting on multiple columns can be implemented easily.
没有评论:
发表评论