[PLUG] Looking for a sed script

Paul Heinlein heinlein at madboa.com
Fri Mar 10 15:56:17 UTC 2006


On Thu, 9 Mar 2006, Sean Whitney wrote:

> I have a customer who has supplied me with several hundred spreadsheets
> containing several hundred rows that contain interface statistics.
>
> Unfortunately, it's in a really useful format like 44.21M or 0.356k
>
> I want to convert these to bits.
>
> I am wondering if sed can
>
> recognize a field in the nature of ( ,44.21M,) and convert that value to
> ( ,44210000, )

I'm not sure sed is the best tool for that sort of manipulation; awk 
or a general-purpose scripting language (perl, python, ruby) would 
probably serve you better. I think this snippet of perl is akin to 
what you want:

   tr/a-z/A-Z/;
   if ( /,([0-9.]+)([BKM]?),/ ) {
     ($num, $mul) = ($1, $2);
     $num *= 10**3 if $mul eq 'K';
     $num *= 10**6 if $mul eq 'M';
     $num *= 10**9 if $mul eq 'B';
     print ',', $num, ',';
   }

-- 
Paul Heinlein <> heinlein at madboa.com <> www.madboa.com



More information about the PLUG mailing list