Author: enrico-sorichetti
Subject: Reply to: How to change 'K' or 'M' use Sort
Posted: Thu May 18, 2017 1:31 pm (GMT 5.5)
not what the TS asked for, but
writing small rexx snippets is like doing crosswords for me![icon_wink.gif]()
try with
the script
(*) it is one of my pet peeves to decouple the real coding from the control data
adding a new multiplier factor will not make the coding to change
the result
doing it with sort could be pretty boring ...
shifting right to find the multiplier factor, and a bunch of ifthen to do the calculations
but probably not impossible
edited the code to deal with BYTES with or without the B suffix
the code assumes that the suffix is VALID
pretty easy to add the check ( done )
_________________
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort![icon_cool.gif]()
Subject: Reply to: How to change 'K' or 'M' use Sort
Posted: Thu May 18, 2017 1:31 pm (GMT 5.5)
not what the TS asked for, but
writing small rexx snippets is like doing crosswords for me

try with
the script
Code: |
#! /usr/bin/env rexx Trace "O" numeric digits 15 in = "356 0M 60M 128K 2G 346Z" mult.B = 1 mult.K = 1024 mult.M = 1024*1024 mult.G = 1024*1024*1024 ou = "" sz = 16 do while ( in \= "" ) parse var in tk in tk = translate(tk) mf = right(tk,1) if datatype(mf,"M") then , tk = strip(tk,,mf) else , mf = "B" if ( symbol("mult."mf) = "VAR" ) then , ou = ou || left(tk * mult.mf,sz," ") else , ou = ou || copies("*",sz-1)" " end say ">>"ou"<<" |
(*) it is one of my pet peeves to decouple the real coding from the control data
adding a new multiplier factor will not make the coding to change
the result
Code: |
>>356 0 62914560 131072 2147483648 *************** << |
doing it with sort could be pretty boring ...
shifting right to find the multiplier factor, and a bunch of ifthen to do the calculations
but probably not impossible
edited the code to deal with BYTES with or without the B suffix
the code assumes that the suffix is VALID
pretty easy to add the check ( done )
_________________
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
