Option 'z' --> Simulate Match Replacement. The input file is scanned for matching strings to be replaced with specified replacement strings.  The replacement strings are specified in a pattern file with the pattern file '#r' operator, see the '-?#' information screens.  The output file containing the input file with replacements is NOT written.

An audit of proposed changes is written to the log file, QTGrep.log.  The log file has three parts:
  1.  header information,
  2.  changed record listing, and
  3.  summary information.
An example of a log file is shown at the end of this information.

The header information lists:
  1. input file name,
  2. input file path,
  3. output file name,
  4. Case - whether or not the input scanned for matches was converted to upper case via the 'u' option, and whether case was respected or ignored in searches, the 'i' option
  5. First or All matches replaced - whether all matches in records are replaced, the 'a' option ON, or whether only the first, the 'a' option OFF,
  6. the number of patterns used for scanning and replacement, and
  7. pattern file name(s).
The changed record listing has two lines for each record containing a match. The first line lists the record number and the record before the replacement.  The second line lists the number of the pattern matched, and the record after replacement of the matching string.  Note that if the 'a' option is on, then a given record will be listed for each proposed changed and thus may be listed in this section more than once.

If the record has been deleted with the '#dr' operator, the changed record is replaced with:

'deleted record'

in the listing.

If the record has been nulled with the '#nr' operator, the changed record is replaced by

'nulled record'

in the listing.

The summary information lists the input path/filename, the number of matching string(s) replaced, the number of record(s) containing matching strings and the total record count of the input file.

This option is a global option and must be specified before any input files are specified.  This option also, by default, 'toggles' the 'a' option so that all matching strings are found and replaced.  If the 'a' option is also invoked with or after the 'z' option, then only the first match in a record will be found and replaced.

The following pattern file:

# replace "FreeMem(argument)" with "argument = FreeMem(argument)"
# using the QTgrep 'r' option
# test with the 'z' option first
# first pattern used to preserve indentation of lines starting with
# desired pattern
^({_w}+)(FreeMem\(([!)]+)\)){_w}*;
#r [<1,1>][<2,1>] = [<1,2>];
{_w}+(FreeMem\(([!)]+)\)){_w}*;
#r \s[<2,1>] = [<1,1>];

Produces the following log file information:

 QTGrep, Linux Vers 2.10. Regular Expression/Keyword Search/Replace. Dec 27 2002
(C) Copyright 1985 - 2003 Terry D. Boldt. All Rights Reserved.
Input File: awkpmsc.c
Input Path: /home/Miscellaneous/Source/QTAwk/Replaced_dir/
Output File: awkpmsc.rpl - Simulated
Case: Mixed/Respect
First/All Matches: All
Replace Patterns: 2 Regular Expressions
Pattern File: replace-FreeMem.exp
.
.
.
2703R: From> FreeMem(ca_str);
1E: To> ca_str = FreeMem(ca_str);
.
.
.
3178R: From> if ( ff_input_fields ) FreeMem(ff_input_fields);
2E: To> if ( ff_input_fields ) ff_input_fields = FreeMem(ff_input_fields);
3305R: From> if ( tmpptr->reky_str != dflt_null_str ) FreeMem(tmpptr->reky_str);
2E: To> if ( tmpptr->reky_str != dflt_null_str ) tmpptr->reky_str = FreeMem(tmpptr->reky_str);   
.
.
.
3364R: From> FreeMem(index_strs2);
1E: To> index_strs2 = FreeMem(index_strs2);
3367R: From> FreeMem(search_pat);
1E: To> search_pat = FreeMem(search_pat);
3384R: From> FreeMem(crnt_str);
1E: To> crnt_str = FreeMem(crnt_str);

/home/Miscellaneous/Source/QTAwk/Replaced_dir/awkpmsc.c
Match Count: 44 (88 Embed)
Pattern 1 Count: 9
Matching Record Count: 45
Records Scanned: 3579
**********************

This option will unconditionally turn off the 'D' option.

Incompatible Options Are:
W
Write Compiled Search Patterns
Z
File  Preview
q
Query, Output Search Expressions
r
Replace Matches (Req Pat File)


© Terry D. Boldt 1997-2005
All Rights Reserved
Last Updated: Feb. 03, 2005