Title

Saturday, 7 February 2015

Replace a whole row containing specific string with another string in PS file


Input file contains .SYNC with incremental numbers: -.sync starts at position 1

 ----+----1----+----2----+----3---   .SYNC 175   UPDATE DB2DF36.RF_PROC_RATES   .SYNC 180   UPDATE DB2DF36.RF_PROC_RATES   .SYNC 185   UPDATE DB2DF36.RF_PROC_RATES   .SYNC 190   UPDATE DB2DF36.RF_PROC_RATES   .SYNC 195   UPDATE DB2DF36.RF_PROC_RATES  

need to apply X all .sync or jcl sort in such a way that, it replaces the whole line of .SYNC with COMMIT;

Output:

 COMMIT;   UPDATE DB2DF36.RF_PROC_RATES   COMMIT;   UPDATE DB2DF36.RF_PROC_RATES   COMMIT;   UPDATE DB2DF36.RF_PROC_RATES   COMMIT;   UPDATE DB2DF36.RF_PROC_RATES   COMMIT;   UPDATE DB2DF36.RF_PROC_RATES  
Answer
 OPTION COPY   INREC IFTHEN=(WHEN=(1,5,CH,EQ,C'.SYNC'),   OVERLAY=(C'COMMIT;',10X))  

Tests for a value, uses OVERLAY to write over the top of the value.

The 10X you can amend, I don't know how long your sequence numbers are.

BUILD=(C'COMMIT;',80X)) can replace the OVERLAY, assuming a record-length of 80. Slightly more intensive use of CPU, but a lazy way to get it done.

It seems from re-reading your question that you might also want to do this with the ISPF editor.

If all your sequence numbers are three digits, you can do it in one shot:

c(hange) 1 p"$sync ###" "commit;"

This limits the position for the find part of the change to column 1, uses a Picture String which says "a speciali character, the letters "sync" (which will respect the CAPS setting), one space, and three numbers" will be changed to "commit;" (again respecting the setting of CAPS). You have to watch that ; is not your command delimiter and change it on option 0 on the primary panel if it is.

If your sequence numbers are longer/shorter as well, I don't think it can be done in one shot.

For safety, of course, you can exclude all the lines, f(find) the .sync (starting in column 1), then c(hange) p"#" " " all nx then change the .sync to commit, remembering all nx.

If you use the command delimiter (other than ;) you can do that all on one line (if you have space).

If you pickle it, there is UNDO, if you have enabled it.

Answer2

Why not try a simple REXX procedure. Something like:

/* REXX */  'EXECIO * DISKR INDD(FINIS' /* Input dataset */  DO QUEUED()   PARSE PULL TXT   IF WORD(TXT, 1) = 'UPDATE' THEN DO   QUEUE 'COMMIT;'   QUEUE TXT   END   END  'EXECIO' QUEUED() 'DISKW OUTDD(FINIS' /* Output dataset */  EXIT  

Save the above procedure in a PDS (e.g. USERID.MYREXX.EXEC(MYPROC)) then run it as part of your job. The JCL to run a REXX procedure is:

//TSOBATCH EXEC PGM=IKJEFT01  //SYSEXEC DD DSN=USERID.MYREXX.EXEC,DISP=SHR  //INDD DD DSN=DATASET.TO.READ,DISP=SHR  //OUTDD DD DSN=DATASET.TO.WRITE,DISP=NEW...  //SYSTSPRT DD SYSOUT=A  //SYSTSIN DD *   %MYPROC  /*  //  

The above procedure reads the dataset assigned to INDD into its internal data queue. It then pulls in one record at a time (PARSE PULL TXT). If that line begins with the "word" UPDATE it then pushes out two lines, a COMMIT; followed by the line it just read. Finally it writes the queued records back to your new output dataset.

If the first word on an input line is not UPDATE then it just ignores that line and goes on to the next one.

No comments:

Post a Comment