Quantcast
Channel: PowerShell General
Viewing all articles
Browse latest Browse all 10624

Conversion from REXX

$
0
0

Apologies if this has been covered, but I did not find anything on a search. I have a REXX script that takes an excel file and converts a linear set of rows to a horizontal format based on a user parameter. Basically this is a trace output and when over a 1000 lines of text is very difficult to review the changing state of various elements.

Example parameter  - ADO FM LSL ST DATE

Example source;

 

FMADO FM LSL ST DATECalculated modified start date227   
VRPSH VR SP START DTLSL Service Period Start Date21  22/02/82
VRPSH VR SP END DTLSL Service Period End Date22  31/12/03
VRPSH VR SP PT INDService Period Emplymnt Status23 N 
VRADO VR NES AUTOLSL NES AUTO24   
VRADO VR NES ADJLSL NES Adjust25   
VRADO VR LSL FT PILLSL FT PIL26   
FMADO FM LSL ST DATECalculated modified start date227   
FMADO FM LSL ST DATECalculated modified start date227   
VRPSH VR SP END DTLSL Service Period End Date22  31/12/03
VRPSH VR SP PT INDService Period Emplymnt Status23 N 
VRADO VR NES AUTOLSL NES AUTO24   
FMADO FM LSL ST DATECalculated modified start date227   

Example output:

 

FMADO FM LSL ST DATECalculated modified start date227   FMADO FM LSL ST DATECalculated modified start date227   
VRPSH VR SP START DTLSL Service Period Start Date21  22/02/82VRPSH VR SP START DTLSL Service Period Start Date21  22/02/82
VRPSH VR SP END DTLSL Service Period End Date22  31/12/03VRPSH VR SP END DTLSL Service Period End Date22  31/12/03
VRPSH VR SP PT INDService Period Emplymnt Status23 N VRPSH VR SP PT INDService Period Emplymnt Status23 N 
VRADO VR NES AUTOLSL NES AUTO24   VRADO VR NES AUTOLSL NES AUTO24   
VRADO VR NES ADJLSL NES Adjust25   VRADO VR NES ADJLSL NES Adjust25   
VRADO VR LSL FT PILLSL FT PIL26   VRADO VR LSL FT PILLSL FT PIL26   
FMADO FM LSL ST DATECalculated modified start date227   FMADO FM LSL ST DATECalculated modified start date227   

There can be a variable number of data rows in each block, and a variable number of iterations of the data. The elements do not always line up like for like and that is fine.

Any one of the blocks may be contain the largest number of elements, and is often the case that either the first or last block is the largest.

The REXX code for a mainframe environment - the IO can be different, but leaving the IO aside will run on windows / Unix etc. It also removes a few columns which saves a manual task.

/* Rexx to cut'n'paste rows into columns */ arg pattern if pattern = '' then
  pattern = 'ADO FM LSL'
"alloc fi(infile) da(colin.csv) shr"
"execio * diskr infile (stem in. finis)"
"free fi(infile)"
within_record = 0
call clear_sheet
do i = 1 to in.0
 parse var in.i w1 ',' w2 ',' w3 ',' w4 ',' w5 ',' w6 ',' w7 ',' w8 ',' .
 if w2 = pattern then
  do
   if within_record = 0 then
    do
     row# = 1
     paste_me = w2","w6","w7","w8
     call paste_a_line
     within_record = 1
     i = i + 1
     parse var in.i w1 ',' w2 ',' w3 ',' w4 ',' w5 ',' w6 ',' w7 ',' w8 ',' .
    end
   if within_record = 1 then
    do
     do until w2 = pattern
      row# = row# + 1
      paste_me = w2","w6","w7","w8
      call paste_a_line
      i = i + 1
      parse var in.i w1 ',' w2 ',' w3 ',' w4 ',' w5 ',' w6 ',' w7 ',' w8 ',' .
     end
    end
   row# = row# + 1
   paste_me = w2","w6","w7","w8
   call paste_a_line
   within_record = 0
   do while row# < 1000
    row# = row# + 1
    paste_me = ',,,'
    call paste_a_line
   end
  end
end
"alloc fi(outfile) da(sheet2.csv) shr"
"execio * diskw outfile (stem sheet2. finis)"
"free fi(outfile)"
exit

paste_a_line:
if sheet2.row# = '' then
 sheet2.row# = paste_me
else
 sheet2.row# = sheet2.row#','paste_me
return

clear_sheet:
sheet2. = ''
do i = 1 to 1000
 sheet2.row# = ''
end
return

 

--------------

If there is any kind soul out there that can A) convert this or B) suggest how this can be done to a novice powershell user, I be very grateful.

 

Many thanks!

 

 

 

 


Viewing all articles
Browse latest Browse all 10624

Trending Articles