Rexx,解析单行文件

时间:2015-02-12 11:12:54

标签: rexx

我正试图找到一种方法来解析Rexx中的文件。每行有两个单词和一个IP地址 例如
位置名称10.0.0.1
我查看了很多文档,我可以让它打印文件中的所有行但我无法弄清楚如何搜索整个文件并使用匹配运算符打印特定行。

4 个答案:

答案 0 :(得分:1)

对于 Regina Rexx ,这个程序应该接近你想要的程序:

   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

答案 1 :(得分:1)

对于Rexx程序来说,这是一项非常简单的任务。

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是开源的,该项目位于http://regina-rexx.sourceforge.net的SourceForge上,您可以从http://sourceforge.net/projects/regina-rexx/files/regina-documentation/3.4/

下载您正在使用的版本的文档

答案 2 :(得分:0)

输入文件: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

代码:

/* 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)"                   

输出1(找到的项目): 发现:LOCATION2


输出2(未找到项目): 对不起搜索项目未找到


答案 3 :(得分: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