I'm trying to find a way to parse a file in Rexx. Each line has two words and an IP address.
Example
Location Name 10.0.0.1
I have looked over a lot of documentation and i can get it to print all the lines in the file but i cannot figure out how to search an entire file and print a specific line by using a match operator.
Asked
Active
Viewed 2,032 times
0

GenericUser
- 87
- 9
-
Which version of Rexx are you using ZOs, Regina etc. What sort of match are you trying to do ??. – Bruce Martin Feb 12 '15 at 20:10
-
I'm not totally sure on which version its, Rexx Scripting through a program called ZOC, "http://www.emtec.com/zoc/documents.html". Their documentation reference says "Regina Rexx" Version 3.4 not sure if that helps. Basically i want to run a match on the first column and and if possible return all 3 values on the match line as variables. – GenericUser Feb 13 '15 at 06:05
4 Answers
1
For Regina Rexx this is a program should be close to what you want:
Call A000_init
Call R000_ReadFile
do while MoreData
parse var line pt1 pt2
if (pt1 == whatever) then do
/* Do some thing */
end
Call R000_ReadFile
end
A000_init:
Yes = 1
No = 0
MoreData = yes
filename = .....
return
R000_ReadFile:
if lines(filename,'N') then do
Line= LineIn(filename)
end; else do
line = ''
MoreData = no
end
Return

Bruce Martin
- 10,358
- 1
- 27
- 38
1
This is a pretty easy task for a Rexx program.
ExpectedLocation = 'Living Room' /* What location are we searching for? */
Signal on NotReady /* Jump to "NotReady:" at end-of-file. */
Do Forever /* ... or at least until EOF or Exit! */
Parse LineIn Word1 Word2 IPAddress . /* Pull apart the three tokens on the line */
Location = Word1 Word2 /* Put the two words of the location back together. */
If Location = ExpectedLocation then Do /* Did we find it? */
Say "Found it :-)" /* Yay! */
Exit /* We're done, stop the program. */
End
End
NotReady: /* We come here at end-of-file. */
Say "Didn't find it :-(" /* Darn! */
Regina is Open Source, the project is on SourceForge at http://regina-rexx.sourceforge.net, and the documentation for the version you're using can be downloaded from http://sourceforge.net/projects/regina-rexx/files/regina-documentation/3.4/

Ross Patterson
- 9,527
- 33
- 48
-
Looks like what i need though how to i define which file to look at? – GenericUser Feb 14 '15 at 04:34
-
As written, this will read from the standard input stream (like any other console-mode program). But you can replace the `Parse LineIn ...whatever...` with `InputLine = LineIn("whatever_file.txt")` and `Parse var InputLine with ...whatever...` and it will read "whatever_file.txt" instead. – Ross Patterson Feb 14 '15 at 11:52
0
Input file : XXXXXX.XXXX.XXXX
***************************** Top of Data
Location1 Name1 11.11.11.11
Location2 Name2 22.22.22.22
Location3 Name3 33.33.33.33
**************************** Bottom of Data
Code:
/* REXX */
/* Author : Ebin Paulose */
/*=============================================================================*/
YourWord = Location2 /*Word which we need to find, here i m giving "Location2"*/
Your_PS = 'XXXXXX.XXXX.XXXX' /*File name where we need to search */
"ALLOC DA('"Your_PS"') F(FILEDD) SHR REUSE" /* Allocate the file */
DO FOREVER
"EXECIO 1 DISKR FILEDD"
IF RC>0 THEN LEAVE
PULL Record /* pull one record from file */
PARSE VAR Record Location " " Name " " IPAddress
/* parse record into 3 parts Location, Name and IPAddress */
IF Location = YourWord THEN do /* check for matching */
SAY 'Found : ' Location
Found = 'Y'
END
END
IF Found ¬= 'Y' THEN DO
SAY 'Sorry Search item Not found'
END
"EXECIO 0 DISKR FILEDD (FINIS"
"FREE F(FILEDD)"
Output 1 (item found) : Found : LOCATION2
Output 2 (item not found) : Sorry Search item Not found

E P
- 11
- 1
- 4
0
filename = 'MY.DATA.SET'
if sysdsn(''''filename'''') <> 'OK' then exit
address 'TSO'
"ALLOCATE FILE(INDD) DATASET('"filename"') SHR REUSE"
"EXECIO DISKR * INDD(STEM file. FINIS)"
"CLOSE FILE(INDD)"
target = 'My Location'
found = 1==0 /* false */
do i = 1 to file.0
card = file.i
parse var card loc1 loc2 ip_address .
found = loc1' 'loc2 == target
if found then leave
end i
if found then
say 'IP address of 'target' is 'ip_address
else
say 'No IP address found for 'target
exit

Adze
- 1