View previous topic :: View next topic
|
Author |
Message |
janaonline
New User
Joined: 13 Dec 2007 Posts: 11 Location: USA, California
|
|
|
|
I need REXX code which does the following:
1. Search a string in all the members
2. If the string is found in any of the member then need to insert a string before the searched string. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
help yourself.
use the search. I know that there are several examples of search all members.
the insert:
after a find hit:
(workline) = linenum .zcsr
insert <yourstuff> before workline |
|
Back to top |
|
|
janaonline
New User
Joined: 13 Dec 2007 Posts: 11 Location: USA, California
|
|
|
|
Thanks for your immediate reply.
IF VAR3 = 'BEFORE' THEN
DO
I = 1
DO K = 1 TO CONTENTS.0
IF POS( VAR1 , CONTENTS.K) > 0 THEN DO
FOUND = 'Y'
OUTPUT.I = VAR2
I = I + 1
END
OUTPUT.I = CONTENTS.K
I = I + 1
END
END
the above code will insert the string as a separate line, but i need it to insert just before the searched string. Could you please help in this??
Thanks!!! |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
you can do this two ways.
1. use execio to read and write the records for the member. this way you would use stems (as your example). I have no suggestion for this, I would not do it this way.
2. use edit macro commands and have your rexx invoke each member via EDIT, then do your FIND, determine line no of hit, insert before lineno. restart you search at lineno + 1 (you insert a line before line 10, line 10 becomes line 11. if you don't start at line 12, you will be in a loop, finding things on the old line 10 -now 11- and inserting again.) |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
If you want to stick with using EXECIO instead of an edit macro (which DOES look to be the better option here), you might go with this:
var1 is the search string
var2 is the insertion string
Code: |
"EXECIO * DISKR ddname (STEM contents. FINIS"
Do i = 1 To contents.0
If Pos(var1,contents.i) <> 0 Then
Do
Queue var2
Queue contents.i
End
Else Queue contents.i
End
"EXECIO "Queued()" DISKW ddname (FINIS"
|
|
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Kevin,
I have failed to say this before, but, you give good advice and your code is clean. |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
Thanks for the kind words. Maybe I should let my boss read this? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Quote: |
Maybe I should let my boss read this? |
Nahhh.....
he might complain that You spend too much time surfing the net |
|
Back to top |
|
|
janaonline
New User
Joined: 13 Dec 2007 Posts: 11 Location: USA, California
|
|
|
|
Thanks a lot for all your suggestion. That was really helpful.. |
|
Back to top |
|
|
|