sorting - Perl-reordering rows in a tsv file -


i'm hoping here can me approach solving following problem. have tsv file 300000 + rows of data wish reorder. short extract below:

src    dest    relationship ck200    ck201    ck200-ck201 ky305    ky306    ky305-ky306 lm102    lm103    lm102-lm103 ky306    ky305    ky306-ky305 ck201    ck200    ck201-ck200 lm103    lm102    lm103-102 

i reorder data in following way.

src    dest    relationship ck200    ck201    ck200-ck201 ck201    ck200    ck201-ck200 ky305    ky306    ky305-ky306 ky306    ky305    ky306-ky305 lm102    lm103    lm102-lm103 lm103    lm102    lm103-lm102 

would best approach store in hash , use kind of sort using 'dest' value key?

any appreciated! i'm not sure of best way of doing efficiency point of view.

thanks, shaw

# original data cat foo.tsv  src    dest    relationship ck200    ck201    ck200-ck201 ky305    ky306    ky305-ky306 lm102    lm103    lm102-lm103 ky306    ky305    ky306-ky305 ck201    ck200    ck201-ck200 lm103    lm102    lm103-102  # store header info head -n 1 foo.tsv > foo_sorted.tsv  # sort remainder, starting @ line 2, , append foo_sorted.tsv tail -n +2 foo.tsv | sort >> foo_sorted.tsv  # show result cat foo_sorted.tsv  src    dest    relationship ck200    ck201    ck200-ck201 ck201    ck200    ck201-ck200   ky305    ky306    ky305-ky306 ky306    ky305    ky306-ky305 lm102    lm103    lm102-lm103 lm103    lm102    lm103-102 

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -