Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to convert a list of intervals into the list of numbers comprised within these intervals?

I have a large file looking like this:

esup_255_3      transdecoder   7655    8192         
esup_6093_1     transdecoder   2732    2774        
esup_25727_1    transdecoder   1       60 
...  

with columns 3 and 4 representing intervals of numbers.

I am trying to modify this file to have the list of numbers comprised within the intervals, listed in a different column (here in column 5) as follows:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

esup_255_3      transdecoder    7655    8192    7655     
esup_255_3      transdecoder    7655    8192    7656
esup_255_3      transdecoder    7655    8192    7657 
esup_255_3      transdecoder    7655    8192     ...    
esup_255_3      transdecoder    7655    8192    8192    
esup_6093_1     transdecoder    2732    2774    2732     
esup_6093_1     transdecoder    2732    2774    2733     
esup_6093_1     transdecoder    2732    2774    ....     
esup_6093_1     transdecoder    2732    2774    2774     
... and so on...

I think Perl may be helpful with this, but I am very new to it. I am only proficient in bash, and here I cannot seem to find the right way to obtain what I need.

>Solution :

Something like this?

    perl -lne 'my ($line, $from, $to) = /^(.*\s(\d+)\s+(\d+)\s*)$/; print "$line\t$_" for $from..$to;' 

When I run it on your snippet it prints out 641 lines:

esup_255_3      transdecoder   7655    8192             7655
esup_255_3      transdecoder   7655    8192             7656
esup_255_3      transdecoder   7655    8192             7657
[...]
esup_255_3      transdecoder   7655    8192             8190
esup_255_3      transdecoder   7655    8192             8191
esup_255_3      transdecoder   7655    8192             8192
esup_6093_1     transdecoder   2732    2774         2732
esup_6093_1     transdecoder   2732    2774         2733
[...]
esup_6093_1     transdecoder   2732    2774         2773
esup_6093_1     transdecoder   2732    2774         2774
esup_25727_1    transdecoder   1       60   1
esup_25727_1    transdecoder   1       60   2
[...]
esup_25727_1    transdecoder   1       60   59
esup_25727_1    transdecoder   1       60   60
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading