Replace text in data sets

With ZOAU, you can change all occurrences of Lines to Records in the members of ${prefix}.my.dsed in the following ways:

  • Issuing a shell command:

    • Option 1:
    dsed "s/Lines/Records/g" "${prefix}.my.dsed"
    
    • Option 2:
    mvscmd --pgm=SORT --args='NOLIST' --sysout=dummy --sortin="${prefix}.my.dsed" --sortout="${prefix}.my.dsed" --sysin=stdin <<zz
     SORT FIELDS=COPY
     INREC FINDREP=(IN=C'Lines',
     OUT=C'Records')
    zz
    
  • Calling an API in Python programs:

    datasets.find_replace("%s.my.dsed" % HLQ, "Lines", "Records")
    

Without ZOAU, to achieve the same purpose, you need to write the following JCL statements:

//*
//* Search for the string 'Lines' in the dataset
//* @@HLQ@@ZOASAMP.MY.DSED and replace each occurrence
//* with 'Records'.
//* Write the output to the same dataset as was used for
//* input.
//* Returns 0 if successful, non-zero if an error occurred.
//*
//DSED EXEC PGM=SORT,                                                 +
//      PARM='NOLIST'
//SYSIN DD *
 SORT FIELDS=COPY
 INREC FINDREP=(IN=C'Lines',
 OUT=C'Records')
/*
//SYSOUT  DD SYSOUT=* 
//SORTIN  DD DSN=@@HLQ@@.ZOASAMP.MY.DSED,DISP=SHR
//SORTOUT DD DSN=@@HLQ@@.ZOASAMP.MY.DSED,DISP=SHR