Print file in particular order in bash

前端 未结 6 404
谎友^
谎友^ 2021-01-13 13:22

I have file with content:

file.txt:

Iteration 1
RAM: +456ms
Cache: +142ms (total +417ms)

Iteration 2
Spec: +152ms
Cache: +149ms (total +413ms)

Iter         


        
6条回答
  •  时光说笑
    2021-01-13 13:51

    Another Perl, using paragraph mode -00

    perl -00 -lnE ' 
                   while(/(^\S+):.+?(\d+)/gm ) {push(@{$kv{$1}},$2)} 
                END { foreach(keys %kv) { print "$_ @{$kv{$_}}" } }    '
    

    with inputs

    $ cat arya.txt
    First launch 1
    RAM: +456ms
    Cache: +142ms (total +417ms)
    
    First launch 2
    Spec: +152ms
    Cache: +149ms (total +413ms)
    
    First launch 3
    RAM: +184ms
    Spec: +172ms
    Searchms: +131ms (total +385ms)
    
    First launch 4
    RAM: +149ms
    Searchms: +188ms
    
    $ perl -00 -lnE ' while(/(^\S+):.+?(\d+)/gm ) {push(@{$kv{$1}},$2)} END { foreach(keys %kv) { print "$_ @{$kv{$_}}" } } ' arya.txt
    RAM 456 184 149
    
    Cache 142 149
    
    Searchms 131 188
    
    Spec 152 172
    
    
    $
    

提交回复
热议问题