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;
FM | ADO FM LSL ST DATE | Calculated modified start date | 2 | 27 | |||
VR | PSH VR SP START DT | LSL Service Period Start Date | 2 | 1 | 22/02/82 | ||
VR | PSH VR SP END DT | LSL Service Period End Date | 2 | 2 | 31/12/03 | ||
VR | PSH VR SP PT IND | Service Period Emplymnt Status | 2 | 3 | N | ||
VR | ADO VR NES AUTO | LSL NES AUTO | 2 | 4 | |||
VR | ADO VR NES ADJ | LSL NES Adjust | 2 | 5 | |||
VR | ADO VR LSL FT PIL | LSL FT PIL | 2 | 6 | |||
FM | ADO FM LSL ST DATE | Calculated modified start date | 2 | 27 | |||
FM | ADO FM LSL ST DATE | Calculated modified start date | 2 | 27 | |||
VR | PSH VR SP END DT | LSL Service Period End Date | 2 | 2 | 31/12/03 | ||
VR | PSH VR SP PT IND | Service Period Emplymnt Status | 2 | 3 | N | ||
VR | ADO VR NES AUTO | LSL NES AUTO | 2 | 4 | |||
FM | ADO FM LSL ST DATE | Calculated modified start date | 2 | 27 |
Example output:
FM | ADO FM LSL ST DATE | Calculated modified start date | 2 | 27 | FM | ADO FM LSL ST DATE | Calculated modified start date | 2 | 27 | ||||||
VR | PSH VR SP START DT | LSL Service Period Start Date | 2 | 1 | 22/02/82 | VR | PSH VR SP START DT | LSL Service Period Start Date | 2 | 1 | 22/02/82 | ||||
VR | PSH VR SP END DT | LSL Service Period End Date | 2 | 2 | 31/12/03 | VR | PSH VR SP END DT | LSL Service Period End Date | 2 | 2 | 31/12/03 | ||||
VR | PSH VR SP PT IND | Service Period Emplymnt Status | 2 | 3 | N | VR | PSH VR SP PT IND | Service Period Emplymnt Status | 2 | 3 | N | ||||
VR | ADO VR NES AUTO | LSL NES AUTO | 2 | 4 | VR | ADO VR NES AUTO | LSL NES AUTO | 2 | 4 | ||||||
VR | ADO VR NES ADJ | LSL NES Adjust | 2 | 5 | VR | ADO VR NES ADJ | LSL NES Adjust | 2 | 5 | ||||||
VR | ADO VR LSL FT PIL | LSL FT PIL | 2 | 6 | VR | ADO VR LSL FT PIL | LSL FT PIL | 2 | 6 | ||||||
FM | ADO FM LSL ST DATE | Calculated modified start date | 2 | 27 | FM | ADO FM LSL ST DATE | Calculated modified start date | 2 | 27 |
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!