|
View previous topic :: View next topic
|
| Author |
Message |
vice_versa Warnings : 1 New User
Joined: 26 Feb 2006 Posts: 19 Location: usa
|
|
|
|
Hello everyone,
I want to change below data
| Code: |
1M 1M 128K
145M 145M 0K
1024M 1024M 0K
0K 0K 0K
0K 0K 0K
256K 256K 64K
256K 256K 64K
1M 1M 64K
512K 512K 64K
22M 22M 128K
60M 60M 256K
1M 1M 128K
1M 1M 128K
198M 198M 0K
1024M 1024M 0K
0K 0K 0K
0K 0K 0K
256K 256K 64K
256K 256K 64K
1M 1M 64K
256K 256K 64K |
change to
| Code: |
1048576 1048576 131072
152043520 152043520 0
1073741824 1073741824 0
0 0 0
0 0 0
262144 262144 65536
262144 262144 65536
1048576 1048576 65536
524288 524288 65536
23068672 23068672 131072
62914560 62914560 262144
1048576 1048576 131072
1048576 1048576 131072
207618048 207618048 0
1073741824 1073741824 0
0 0 0
0 0 0
262144 262144 65536
262144 262144 65536
1048576 1048576 65536
262144 262144 65536
|
thanks in advance |
|
| Back to top |
|
 |
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
I don't know if this is the most efficient way of doing it, but here is a sample rexx. You can expand it to process the complete dataset.
| Code: |
/******************rexx*******************/
string = '0M 60M 128K'
parse var string col1 col2 col3 .
do i = 1 to 3
interpret "temp = col"i
select
when pos('K',temp) \= 0 then do
interpret "col"i "=" (substr(temp,1,(pos('K',temp)-1))) * 1024
end
when pos('M',temp) \= 0 then do
interpret "col"i "=" (substr(temp,1,(pos('M',temp)-1))) * 1048576
end
otherwise
end
end
string = left(col1,10) || left(col2,10) || left(col3,10)
say string |
Output:
Hope this helps. |
|
| Back to top |
|
 |
enrico-sorichetti
Superior Member

Joined: 14 Mar 2007 Posts: 10903 Location: italy
|
|
|
|
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 ) |
|
| Back to top |
|
 |
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
| Quote: |
| I don't know if this is the most efficient way of doing it |
Now I know that was not  |
|
| Back to top |
|
 |
enrico-sorichetti
Superior Member

Joined: 14 Mar 2007 Posts: 10903 Location: italy
|
|
|
|
probably You have not written as many lines of Rexx code as I have done  |
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
| Quote: |
doing it with sort could be pretty boring ...
|
I thought of taking up some of that, before I get to my much boring work . There could be better ways, but here is one of them that I can think of now.
| Code: |
//SYSIN DD *
OPTION COPY
OUTREC IFTHEN=(WHEN=INIT,
OVERLAY=(1:1,80,SQZ=(SHIFT=LEFT))),
IFTHEN=(WHEN=INIT,
FINDREP=(INOUT=(C'K',C',1024,',
C'M',C',1048576,',
C'G',C',1073741824,'))),
IFTHEN=(WHEN=INIT,
PARSE=(%1=(ENDBEFR=C',',FIXLEN=10,REPEAT=6)),
OVERLAY=(%1,UFF,MUL,%2,UFF,M10,LENGTH=16,
01:01,16,JFY=(SHIFT=LEFT),
%3,UFF,MUL,%4,UFF,M10,LENGTH=16,
17:17,16,JFY=(SHIFT=LEFT),
%5,UFF,MUL,%6,UFF,M10,LENGTH=16,
33:33,16,JFY=(SHIFT=LEFT))) |
For the OP's input data provided in SORTIN, SORTOUT had
| Code: |
1048576 1048576 131072
152043520 152043520 0
1073741824 1073741824 0
0 0 0
0 0 0
262144 262144 65536
262144 262144 65536
1048576 1048576 65536
524288 524288 65536
23068672 23068672 131072
62914560 62914560 262144
1048576 1048576 131072
1048576 1048576 131072
207618048 207618048 0
1073741824 1073741824 0
0 0 0
0 0 0
262144 262144 65536
262144 262144 65536
1048576 1048576 65536
262144 262144 65536 |
|
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|