多行替换

发布于 2024-12-13 17:32:45 字数 331 浏览 2 评论 0原文

我正在尝试在多个 JCL 中执行搜索替换,但我需要多行功能,我需要替换多个行。 示例:

//STEP1 EXEC PGM=DUMY,PARAM=XPTO

转换为

//STEP1 EXEC PGM=WORKS,PARAM=THAT
//SOMEDD DSN=DSN.WITH.SOMETHING
//SYSTIN
SOME MORE PARAMETERS

我研究了文件辅助批处理,但它似乎只支持 STRING 替换,而不支持多行。 我认为 REXX 可能会这样做,但我对此一无所知。

有什么想法吗?

I'm trying to perform a search-replace in several JCLs but I need multi-line capabilities, I need to replace a line for several.
Example:

//STEP1 EXEC PGM=DUMY,PARAM=XPTO

transform into

//STEP1 EXEC PGM=WORKS,PARAM=THAT
//SOMEDD DSN=DSN.WITH.SOMETHING
//SYSTIN
SOME MORE PARAMETERS

I looked into file-aid batch processing but it seems to only support STRING replacement without multi-line support.
I thing REXX might do it but I have no knowledge in it.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

黄昏下泛黄的笔记 2024-12-20 17:32:45

有一些商业产品可以理解 JCL 语法并可以执行此类操作。 JOB/SCAN 是其中之一,我相信还有其他在这个产品领域也可以做到。

如果您没有这样的产品,这没有任何帮助,所以我们回到您的 Rexx 评论。是的,您可以使用 Rexx 来完成此操作,但您将解析 JCL。根据您的要求,这可能并不简单。 Rexx 没有正则表达式匹配,而这是解析时通常使用的。这是可以完成的,如果您不打算做任何比您所指示的更复杂的事情,那么对于 Rexx 程序员来说可能并不太难 - 也许这是成为一名程序员的机会。 Rexx 的设计目标之一是让编程变得更容易。

另一种方法是使用 Perl,将 PDS 成员复制到 Unix 文件系统,以便可以处理它们,然后在完成后将它们复制回来。假设您正在运行 z/OS 的相对最新版本,并且您的系统程序员已经安装了 Perl 的 z/OS 端口,这是一个免费项目。

如果您愿意将受影响的成员复制到 Unix 文件系统,您可以使用 awk。我只接触过 awk,但它的优点是默认存在,没有人需要安装默认情况下不存在的任何东西(Perl)。

There are commercial products that understand JCL syntax and can do this sort of thing. JOB/SCAN is one, I'm sure others in this product space can do it too.

Which is of no help if you don't have such a product, so we're back to your Rexx comment. Yes, you can do this with Rexx, but you're going to be parsing JCL. This can be non-trivial depending on your requirements. Rexx doesn't have regular expression matching, which is what one normally uses when parsing. It can be done, and if you aren't seeking to do anything much more complicated that what you've indicated then it's probably not too difficult for a Rexx programmer - perhaps this is an opportunity to become one. Rexx had, as one of its design goals, to make programming easier.

An alternative would be to use Perl, copying the PDS members to the Unix file system so you can process them, then copying them back when you're done. Presuming you're running a relatively current release of z/OS and your Systems Programmer(s) have installed the z/OS port of Perl, which is a no-cost item.

If you're willing to copy the affected members to the Unix file system, you may be able to do this with awk. I've only dabbled with awk, but it has the advantage of just being there by default, no one would have to install anything (Perl) that isn't already there by default.

幻想少年梦 2024-12-20 17:32:45

以下是我想到的可能性:

  1. 您可以编写一个简单的 COBOL 程序,该程序将搜索所需的 STRING 并替换为您想要/需要添加的任何内容。
  2. 您还可以编写 REXX EXEC 来执行此操作,这可能不需要解析读取的代码行。我想简单的 IF 条件就可以了。

但您可能会遇到一些挑战,当然这些挑战是可以避免的。

  1. 如果您搜索的内容同时存在一些其他参数怎么办?就像

    //STEP1 EXEC PGM=DUMY,PARAM=XPTO,PARM1='X'

  2. 如果搜索字符串跨越多行怎么办?就像

    //STEP1 EXEC PGM=DUMY,

    // PARAM=XPTO

Here are the possibilities that I have in my mind:

  1. You can write a simple COBOL program which would search for the required STRING and replace with whatever you want/need to add.
  2. You can also write a REXX EXEC to perform this, which may not need to parse the line of code that gets read. Simple IF condition would do, i suppose.

But here are some challenges you would have and of course are avoidable.

  1. What if some other parameters exist along with what you search for? like

    //STEP1 EXEC PGM=DUMY,PARAM=XPTO,PARM1='X'

  2. What if the search string is spanned across more than one line? like

    //STEP1 EXEC PGM=DUMY,

    // PARAM=XPTO

吻风 2024-12-20 17:32:45

这是一个简单的 TSO/ISPF 编辑宏,将实现您的示例。当然,这非常粗糙,但可以作为如何编辑 JCL 的示例。

    ISREDIT MACRO ()                                                                
        CONTROL NOFLUSH NOPROMPT   LIST   CONLIST   SYMLIST   MSG               
        ISREDIT CHANGE ' PGM=DUMY' ' PGM=WORKS'                                 
        ISREDIT CHANGE 'XPTO'     'THAT'                                        
        ISREDIT (ROW1,COL1) = CURSOR                                            
        ISREDIT LINE_AFTER &ROW1 = "//SOMEDD DD DSN=DSN.WITH.SOMTHING,DISP=SHR" 
        SET &ROW1 = &ROW1 + 1                                                   
        ISREDIT LINE_AFTER &ROW1 = "//SYSTSIN DD *"                             
        SET &ROW1 = &ROW1 + 1                                                   
        ISREDIT LINE_AFTER &ROW1 = "SOME MORE PARAMETERS"                       
        EXIT CODE(0) 

Here is a simple TSO/ISPF edit macro that will implement your example. Of course this is very crude but serves as an example of how JCL might be edited.

    ISREDIT MACRO ()                                                                
        CONTROL NOFLUSH NOPROMPT   LIST   CONLIST   SYMLIST   MSG               
        ISREDIT CHANGE ' PGM=DUMY' ' PGM=WORKS'                                 
        ISREDIT CHANGE 'XPTO'     'THAT'                                        
        ISREDIT (ROW1,COL1) = CURSOR                                            
        ISREDIT LINE_AFTER &ROW1 = "//SOMEDD DD DSN=DSN.WITH.SOMTHING,DISP=SHR" 
        SET &ROW1 = &ROW1 + 1                                                   
        ISREDIT LINE_AFTER &ROW1 = "//SYSTSIN DD *"                             
        SET &ROW1 = &ROW1 + 1                                                   
        ISREDIT LINE_AFTER &ROW1 = "SOME MORE PARAMETERS"                       
        EXIT CODE(0) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文