Skip to content

Instantly share code, notes, and snippets.

@grtodd
Last active August 29, 2015 14:09
Show Gist options
  • Save grtodd/9285d1c3e5873b796e5b to your computer and use it in GitHub Desktop.
Save grtodd/9285d1c3e5873b796e5b to your computer and use it in GitHub Desktop.
Oneliner Munging with perl

From an answer to a Stack Overflow query ...

This perl:

$ perl -MDDP -lane 'BEGIN{ local @ARGV=shift; @tmp = map {[split]} <>; p @tmp }
   $name = s/>//r if /^>/ ; push @out , [ $name, length $_ ] if !/^>/ ;  
   END{ p @out }' output.txt datafile2.txt 

Produces ....


[     
    [0] [                 
        [0] "one",     
        [1] 5  
    ],   
    [1] [   
        [0] "two",        
        [1] 3         
    ],                                                                      
    [2] [    
        [0] "three", 
        [1] 1  
    ]    
]  

[                                                                           
    [0] [                                                                   
        [0] "one",                                                          
        [1] 7                                                               
    ],                                                                      
    [1] [                                                                   
        [0] "two",                                                          
        [1] 7                                                               
    ],                                                                      
    [2] [                                                                   
        [0] "three",                                                        
        [1] 2                                                               
    ]                                                                       
]         

>one
AAAAABB
>two
BBBVFVF
>three
CS
one 5
two 3
three 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment