[PLUG] Looking for a sed script

Lancashire, Pete plancashire at ci.portland.or.us
Fri Mar 10 16:04:20 UTC 2006


k = 1024 or 1000 ?

easy one to mis :)

-pete

> -----Original Message-----
> From: Paul Heinlein [mailto:heinlein at madboa.com]
> Sent: Friday, March 10, 2006 7:56 AM
> To: General Linux/UNIX discussion and help; civil and on-topic
> Subject: Re: [PLUG] Looking for a sed script
> 
> 
> 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
> _______________________________________________
> PLUG mailing list
> PLUG at lists.pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug
> 



More information about the PLUG mailing list