Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

REXX data manipulation

Status
Not open for further replies.

firedotwater

Systems Engineer
Oct 3, 2022
3
CH
Hello everyone I have a small rexx data manipulation issue. I have a huge file with a lot of information and I want to only print / save the my necessary information from the file.

Code:
/*REXX*/                                         
file = "my.dsn.to.file"                
"ALLOC FI(file) DSN('"file"') SHR"       
"EXECIO * DISKR file(STEM file. FINIS"   
"FREE FI(file)"                              
                                                  
DO x = 1 TO file.0                       
   JNAME = SUBSTR(file.x,2,9)            
   DATE  = SUBSTR(file.x,20,10)          
   RC    = SUBSTR(file.x,94,4)           
   SAY DATE JNAME RC                                   
END

With this I will receive my wanted information, but now especially in the date I have multiple entries with the same date. Now I am confused how can I merge /purge them together? I tried to make an easy counter but it didn’t work quite like I wanted.

Could someone give me an hint or a direction?[bigsmile]
 
post example of data: what is your output now and what you want to achieve
 
Is it that you only want one entry per date, or do you want to have all entries for a given date shown together?

If you can provide a more precise 'spec', there are several followers here who can provide direction.

Frank Clarke
--America's source for adverse opinions since 1943.
 
I tried this:

firedotwater.rex
Code:
file [COLOR=#a52a2a][b]=[/b][/color] [COLOR=#ff00ff]"firedotwater.txt"[/color]                

my_cmd [COLOR=#a52a2a][b]=[/b][/color] [COLOR=#ff00ff]"cat"[/color] file
my_cmd_queue [COLOR=#a52a2a][b]=[/b][/color] my_cmd [COLOR=#ff00ff]"| rxqueue"[/color]
my_cmd_queue
[COLOR=#a52a2a][b]do[/b][/color] i[COLOR=#a52a2a][b]=[/b][/color]1 [COLOR=#a52a2a][b]while[/b][/color] [COLOR=#008b8b]queued()[/color] [COLOR=#a52a2a][b]\=[/b][/color] 0
  [COLOR=#a52a2a][b]parse pull[/b][/color] file.i
[COLOR=#a52a2a][b]end[/b][/color]
file.0 [COLOR=#a52a2a][b]=[/b][/color] i-1

[COLOR=#a52a2a][b]say[/b][/color] [COLOR=#ff00ff]"Reading all records from file """[/color][COLOR=#a52a2a][b]||[/b][/color]file[COLOR=#a52a2a][b]||[/b][/color][COLOR=#ff00ff]""":"[/color]
dates [COLOR=#a52a2a][b]=[/b][/color] [COLOR=#ff00ff]""[/color]
fruits [COLOR=#a52a2a][b]=[/b][/color] [COLOR=#ff00ff]""[/color]
[COLOR=#0000ff]/* initialize stem for counting fruits on a date */[/color]
date_fruit_count. [COLOR=#a52a2a][b]=[/b][/color] 0
[COLOR=#a52a2a][b]do x [/b][/color][COLOR=#a52a2a][b]=[/b][/color] 1 [COLOR=#a52a2a][b]to[/b][/color] file.0                       
   my_fruit [COLOR=#a52a2a][b]=[/b][/color] [COLOR=#008b8b]strip(SUBSTR([/color]file.x[COLOR=#a52a2a][b],[/b][/color]2[COLOR=#a52a2a][b],[/b][/color]9[COLOR=#008b8b]))[/color]            
   my_date  [COLOR=#a52a2a][b]=[/b][/color] [COLOR=#008b8b]strip(SUBSTR([/color]file.x[COLOR=#a52a2a][b],[/b][/color]20[COLOR=#a52a2a][b],[/b][/color]10[COLOR=#008b8b]))[/color]          
   my_rcx   [COLOR=#a52a2a][b]=[/b][/color] [COLOR=#008b8b]SUBSTR([/color]file.x[COLOR=#a52a2a][b],[/b][/color]94[COLOR=#a52a2a][b],[/b][/color]4[COLOR=#008b8b])[/color]           
   [COLOR=#a52a2a][b]say[/b][/color] my_date my_fruit my_rcx
   [COLOR=#a52a2a][b]if[/b][/color] [COLOR=#008b8b]wordpos([/color]my_date[COLOR=#a52a2a][b],[/b][/color] dates[COLOR=#008b8b])[/color] [COLOR=#a52a2a][b]=[/b][/color] 0 [COLOR=#a52a2a][b]then[/b][/color] [COLOR=#a52a2a][b]do[/b][/color]
     dates [COLOR=#a52a2a][b]=[/b][/color] dates my_date   
   [COLOR=#a52a2a][b]end[/b][/color]

   [COLOR=#a52a2a][b]if[/b][/color] [COLOR=#008b8b]wordpos([/color]my_fruit[COLOR=#a52a2a][b],[/b][/color] fruits[COLOR=#008b8b])[/color] [COLOR=#a52a2a][b]=[/b][/color] 0 [COLOR=#a52a2a][b]then[/b][/color] [COLOR=#a52a2a][b]do[/b][/color]
     fruits [COLOR=#a52a2a][b]=[/b][/color] fruits my_fruit
   [COLOR=#a52a2a][b]end[/b][/color]
   [COLOR=#a52a2a][b]if[/b][/color] date_fruit_count.my_date.my_fruit [COLOR=#a52a2a][b]=[/b][/color] 0 [COLOR=#a52a2a][b]then[/b][/color] [COLOR=#a52a2a][b]do[/b][/color]
      date_fruit_count.my_date.my_fruit [COLOR=#a52a2a][b]=[/b][/color] 1
   [COLOR=#a52a2a][b]end[/b][/color]
   [COLOR=#a52a2a][b]else[/b][/color] [COLOR=#a52a2a][b]do[/b][/color]
      date_fruit_count.my_date.my_fruit [COLOR=#a52a2a][b]=[/b][/color] date_fruit_count.my_date.my_fruit + 1
   [COLOR=#a52a2a][b]end[/b][/color]
[COLOR=#a52a2a][b]end[/b][/color]
[COLOR=#0000ff]/* Report */[/color]
[COLOR=#a52a2a][b]say[/b][/color]
[COLOR=#a52a2a][b]say[/b][/color] [COLOR=#ff00ff]"Report:"[/color]
[COLOR=#a52a2a][b]say[/b][/color] [COLOR=#ff00ff]"======="[/color]
[COLOR=#a52a2a][b]say[/b][/color] [COLOR=#ff00ff]"Dates found :"[/color] dates
[COLOR=#a52a2a][b]say[/b][/color] [COLOR=#ff00ff]"Fruits found:"[/color] fruits
[COLOR=#a52a2a][b]say[/b][/color]
[COLOR=#a52a2a][b]say[/b][/color] [COLOR=#ff00ff]"Fruits found on given dates:"[/color]
[COLOR=#a52a2a][b]do i [/b][/color][COLOR=#a52a2a][b]=[/b][/color] 1 [COLOR=#a52a2a][b]to[/b][/color] [COLOR=#008b8b]words([/color]dates[COLOR=#008b8b])[/color]
  my_date [COLOR=#a52a2a][b]=[/b][/color] [COLOR=#008b8b]word([/color]dates[COLOR=#a52a2a][b],[/b][/color] i[COLOR=#008b8b])[/color]
  out_line [COLOR=#a52a2a][b]=[/b][/color] my_date[COLOR=#a52a2a][b]||[/b][/color][COLOR=#ff00ff]":"[/color]
  [COLOR=#a52a2a][b]do j [/b][/color][COLOR=#a52a2a][b]=[/b][/color] 1 [COLOR=#a52a2a][b]to[/b][/color] [COLOR=#008b8b]words([/color]fruits[COLOR=#008b8b])[/color]
    my_fruit [COLOR=#a52a2a][b]=[/b][/color] [COLOR=#008b8b]word([/color]fruits[COLOR=#a52a2a][b],[/b][/color] j[COLOR=#008b8b])[/color]
    my_fruit_count [COLOR=#a52a2a][b]=[/b][/color] date_fruit_count.my_date.my_fruit
    [COLOR=#a52a2a][b]if[/b][/color] my_fruit_count [COLOR=#a52a2a][b]<>[/b][/color] 0 [COLOR=#a52a2a][b]then[/b][/color] [COLOR=#a52a2a][b]do[/b][/color]
      out_line [COLOR=#a52a2a][b]=[/b][/color] out_line my_fruit[COLOR=#a52a2a][b]||[/b][/color][COLOR=#ff00ff]"="[/color] my_fruit_count
    [COLOR=#a52a2a][b]end[/b][/color]
  [COLOR=#a52a2a][b]end[/b][/color]
  [COLOR=#a52a2a][b]say[/b][/color] out_line
[COLOR=#a52a2a][b]end[/b][/color]

With this given data file
firedotwater.txt
Code:
>apple             2022-10-01                                                                RC01
 pear              2022-10-02                                                                RC02
 pear              2022-10-02                                                                RC03
 apple             2022-10-01                                                                RC04
 pear              2022-10-03                                                                RC05
 apple             2022-10-03                                                                RC06
 apple             2022-10-03                                                                RC07
 pear              2022-10-03                                                                RC08
 pear              2022-10-03                                                                RC09
 banana            2022-10-04                                                                RC10
 apple             2022-10-04                                                                RC11
 apple             2022-10-05                                                                RC12
 apple             2022-10-05                                                                RC13
 apple             2022-10-05                                                                RC14

it gives this result:
Code:
$ rexx firedotwater.rex
Reading all records from file "firedotwater.txt":
2022-10-01 apple RC01
2022-10-02 pear RC02
2022-10-02 pear RC03
2022-10-01 apple RC04
2022-10-03 pear RC05
2022-10-03 apple RC06
2022-10-03 apple RC07
2022-10-03 pear RC08
2022-10-03 pear RC09
2022-10-04 banana RC10
2022-10-04 apple RC11
2022-10-05 apple RC12
2022-10-05 apple RC13
2022-10-05 apple RC14

Report:
=======
Dates found :  2022-10-01 2022-10-02 2022-10-03 2022-10-04 2022-10-05
Fruits found:  apple pear banana

Fruits found on given dates:
2022-10-01: apple= 2
2022-10-02: pear= 2
2022-10-03: apple= 2 pear= 3
2022-10-04: apple= 1 banana= 1
2022-10-05: apple= 3
 
Holy moly, wow that's impressive. That's exactly what I wanted.
Perfect, many thanks @mikrom!



Greetins
Fire
 
@firedotwater: and did you understand how it works ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top