S Search and Replace

Preliminary note: The "Search and Replace" command will only function in Modify mode (M command). In Non Modify mode, a count is only made of how often the replacement would have been made (display of the number of hits).

S [-] [n], ...= [len] item2 [, ...= [len] item2 ] .... [, opt]

S .... represents a single search argument as described in the previous section "Search for Character Strings (Simple Search Argument)".

len optional length definition. When replacing, item2 will be repeated until the specified length, len is attained. If it is not specified, len = length of the replacement string.

item2 Replacement string:  C'...' | L'...' | X'...'

The statement: ...= [len] item2 can be repeated as often as required. Commas ("or" conditions) should be used as delimiters.

If the command line is not sufficient to hold the statements, entering S,()[,opt] will produce the Search mask. Formats 3 and 4 of the Search command can also be used for Search and Replace:

S, %name [, opt] | S, ( s-fil ) [, opt].

The option [,opt] can also be entered in the Search mask / s-fil after the last pair of search string=replace string statements.

opt C | R | A | Q

option to control the replacement process.

C The C option (Change) will cause an exact swap of the search and replacement strings in the records. The record lengths in this case will be amended accordingly. This option is analogous to replacement in EDT.

Normally, (no C option specified), the replacement string will overwrite the detected search string. The length of the modified record will then not be amended, even if the search string and replacement string are of different lengths.

The C option is only applicable for ISAM files, or SAM files converted to ISAM format. RECFORM=V is also a prerequisite for this option.

R Reverse. The search and replace operation within the records will take place in reverse order, i.e. from right to left. Multiple search and replace conditions cannot be combined in this mode.

Only the C option (see above) can be combined with the R option, i.e. CR.

Standard: The replacement proceeds from left to right.

A All search hits within a record are replaced (analogous to the EDT command: @ON...CA'...'T'...').

Standard: The replacement will only be carried out for the first hit in each record.

If neither the C or A options are specified, then the first hit in each record will be replaced with the replacement string.

Q Query: The user is asked for confirmation before each replacement. The window is positioned 20 columns to the left of the hit. Pressing the DUE1 (ENTER) key will proceed with replacing the search string. Pressing the K3 key will prevent the replacement taking place. After pressing either key (DUE1/K3), the search process continues to the next occurrence. The search process can be terminated by overwriting the S command in the command line.

Standard: no Query mode. The string will be replaced without asking the user.

Notes:

The C, A, and Q options can also be combined: CA / CQ / AQ / CAQ. However, the sequence of these combinations is fixed. The C option, if required, must be specified first, then A, and finally the Q option. For example, CA is equivalent to the Change All command of EDT. CAQ is a variation, whereby the user is asked to confirm each replacement or not.

When using the CAQ (Change All Query) option with differing length search and replacement strings, it can occur that some characters do not appear at the end of the current record (i.e. the record appears to be truncated). This has no actual effect on the underlying data.

If the C option is not specified with a Search and Replace command, then the following should be noted:

If the replacement string (item2) is longer than the search string (item1), then data to the right of item1 will be overwritten by item2 .

If the replacement string (item2) is shorter than the search string (item1), then the rest of item1 will remain unchanged.

ISAM: no replacement within the key will take place.

PAM: Search over Block Boundaries

The search string does not have to be contained fully within a data block when searching PAM files. If the search item (e.g. 'DATABASE') starts at the end of a PAM block, and continues at the beginning of another block (e.g. 'DA' + 'TABASE'), then this will be recognised by CFS, flagged as a hit, and the replacement will take place.

Examples:

S,C'C''passw'''=C'C''new-passw''',CAQ

In ISAM mode, a search will be made for the character string C'passw'. For each occurrence of this string, the user will be asked if it should be replaced with C'new-passw'. Pressing the DUE1 key will confirm the replacement, and the search will be continued. Pressing the K3 key will suppress the replacement and continue the search process. The data to the right will be shifted when the replacement takes place.

S,:9:''=60X'FF'

The record contents from column 9 to column 60 (beginning of record is at column 1) of each record from the first displayed, to the end of the file, is overwritten with X'FF'.

S,:90:X'FF'+:1990:X'FA00'+:1545:''=5X'FF'

A search is made for all records containing X'FF' in column 90 and X'FA00' in column 1990, from the first displayed record to the end of the file. All records that fulfill these conditions will have the column range from 1545 to 1549 overwritten with X'FF'.

S,'ABCD'='',CA

All columns of all records from the first currently displayed to the end of the file are searched for the character string ABCD. If found, it is removed. This removal can occur more than once per record. (option A). Option C causes the resulting record to be shortened.

S,()

This command will cause the Search mask to be displayed, in which a user has entered the following:

} dd.mm.yy hh:mm:ss HOST: ........ TSN: .... {
} COMMAND :SP %cap {
} please enter/modify search-item below {
} S,L'a'='A',L'b'='B',L'c'='C',L'd'='D',L'e'='E',L'f'='F',L'g'='G',L'h'='H',L'i'= {
} 'I',L'j'='J',L'k'='K',L'L'='L',L'm'='M',L'n'='N',L'o'='O',L'p'='P',L'q'='Q',L'r {
} '='R',L's'='S',L't'='T',L'u'='U',L'v'='V',L'w'='W',L'x'='X',L'y'='Y',L'z'='Z',L {
} 'ae'='Ae',L'oe'='Oe',L'ue'='Ue',L'ä'='Ä',L'ö'='Ö',L'ü'='Ü',A {
} {
} {
} {
} {
} {
} {
} {
} {
} {
} {
} {
} {
} {
} DUE1: start search / K1: abort / Command SP %name: save search-item / F3: HC {
} Activate / Redisplay saved search-item with Command: S,%name / S?,%name {
} param-set saved as %CAP in CFS.JRSAVE.HILBERT {

All lowercase letters (see option A at the end of the mask entry) are converted to uppercase. Entering the command SP %CAP will cause these Search and Replace statements to be saved under the name %CAP in the file CFS.JRSAVE [.jobname], or to a file assigned with the following command: /FILE file, LINK=JRSAVE. The exact rules by which the names of the JRSAVE files are created are described in Chapter 27, "Files created by CFS", under CFS.JRSAVE.

S,%CAP

The Search and/or Replace statements saved under the name %CAP are executed.

S?,%CAP

The Search and/or Replace statements saved under the name %CAP will be displayed on the screen (see above), and can then be further modified or executed.