\" $NetBSD: qsubst.1,v 1.6 2017/02/22 14:01:40 abhinav Exp $
\"
\" This file is in the public domain.
Dd September 4, 1999
Dt QSUBST 1
Os
Sh NAME
Nm qsubst
Nd query-replace strings in files
Sh SYNOPSIS
Nm
Ar str1
Ar str2
Op Ar flags
Ar file
Op Ar file Op Ar ...
Sh DESCRIPTION
Nm
reads its options (see below) to get a list of files.
For each file on this list, it then replaces
Ar str1
with
Ar str2
wherever possible in that file, depending on user input (see below).
The result is written back onto the original file.
Pp
For each potential substitution found, the user is prompted with a few
lines before and after the line containing the string to be
substituted.
The string itself is displayed using the terminal's standout mode, if any.
Then one character is read from the terminal.
This is then interpreted as follows (this is designed to be like Emacs'
query-replace-string):
Bl -tag -width "space" -compact -offset indent
It space
Replace this occurrence and go on to the next one.
It \&.
Replace this occurrence and don't change any more in this file (i.e., go
on to the next file).
It \&,
Tentatively replace this occurrence.
The lines as they would look if the substitution were made are printed out.
Then another character is read and it is used to decide the result as if
the tentative replacement had not happened.
It n
Don't change this one; just go on to the next one.
It \&^G
Don't change this one or any others in this file, but instead simply go
on to the next file.
It \&!
Change the rest in this file without asking, then go on to the next
file (at which point
Nm
will start asking again).
It \&?
Print out the current filename and ask again.
El
Pp
The first two arguments to
Nm
are always the string to replace and
the string to replace it with.
The options are as follows:
Bl -tag -width "-F filename" -compact -offset indent
It Fl w
The search string is considered as a C symbol; it must be bounded by
non-symbol characters.
This option toggles.
Pf ( Sq w
for
Sq word . )
It Fl \&!
It Fl go
It Fl noask
Enter \&! mode automatically at the beginning of each file.
It Fl nogo
It Fl ask
Negate
Fl go ,
that is, ask as usual.
It Fl c Ns Ar N
(Where
Ar N
is a number.)
Give
Ar N
lines of context above and below the
line with the match when prompting the user.
It Fl CA Ns Ar N
(Where
Ar N
is a number.)
Give
Ar N
lines of context above the line with the match when prompting the user.
It Fl CB Ns Ar N
(Where
Ar N
is a number.)
Give
Ar N
lines of context below the line with the match when prompting the user.
It Fl f Ar filename
The
Ar filename
argument is one of the files
Nm
should perform substitutions in.
It Fl F Ar filename
Nm
reads
Ar filename
to get the names of files to perform substitutions in.
The names should appear one to a line.
El
Pp
The default amount of context is
Fl c2 ,
that is, two lines above and two lines below the line with the match.
Pp
Arguments not beginning with a
Fl \&
sign in the options field are implicitly preceded by
Fl f .
Thus,
Fl f
is really needed only when the file name begins with a
Fl \&
sign.
Pp
Nm
reads its options in order and processes files as it gets them.
This means, for example, that a
Fl go
will affect only files named after the
Fl go .
Pp
The most context you can get is ten lines each, above and below.
Pp
Ar str1
is limited to 512 characters; there is no limit on the size of
Ar str2 .
Neither one may contain a NUL.
Pp
NULs in the file may cause
Nm
to make various mistakes.
Pp
If any other program modifies the file while
Nm
is running, all
bets are off.
Sh AUTHORS
An der Mouse Aq Mt
[email protected]