unix - How to move all lines with the first 10 characters that are identical to a common column? -


i have file has 1 column looks this:

chr1 106623419 chr1 106623434 chr1 106623436 chr1 110611528 chr1 110611536 chr1 110611550 chr1 110611552 chr1 111216608 chr1 111216621 chr1 111216624 chr1 111216627 chr1 111216628 

i want sort selecting lines share same first 10 characters , put them in own column this

chr1 106623419  chr1 110611528  chr1 111216608 chr1 106623434  chr1 110611536  chr1 111216621 chr1 106623436  chr1 110611550  chr1 111216624                 chr1 110611552  chr1 111216627                                 chr1 111216628 

perl solution:

perl -ne 'chomp;           push @{ $h{ substr $_, 0, 10 } }, substr $_, 10;           }{           while (grep @$_, values %h) {               $p (keys %h) {                   $s = shift @{ $h{$p} };                   print $s ? "$p$s" : "\t", "\t";               }               print "\n";           }' input.file 

how works: creates hash map of prefix -> array of suffixes. once input on (}{), shifts values arrays 1 one , prints them columns. if no value remains in array, tab printed instead.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -