xref: /netbsd-src/usr.bin/qsubst/qsubst.1 (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1.\"	$NetBSD: qsubst.1,v 1.6 2017/02/22 14:01:40 abhinav Exp $
2.\"
3.\" This file is in the public domain.
4.Dd September 4, 1999
5.Dt QSUBST 1
6.Os
7.Sh NAME
8.Nm qsubst
9.Nd query-replace strings in files
10.Sh SYNOPSIS
11.Nm
12.Ar str1
13.Ar str2
14.Op Ar flags
15.Ar file
16.Op Ar file Op Ar ...
17.Sh DESCRIPTION
18.Nm
19reads its options (see below) to get a list of files.
20For each file on this list, it then replaces
21.Ar str1
22with
23.Ar str2
24wherever possible in that file, depending on user input (see below).
25The result is written back onto the original file.
26.Pp
27For each potential substitution found, the user is prompted with a few
28lines before and after the line containing the string to be
29substituted.
30The string itself is displayed using the terminal's standout mode, if any.
31Then one character is read from the terminal.
32This is then interpreted as follows (this is designed to be like Emacs'
33query-replace-string):
34.Bl -tag -width "space" -compact -offset indent
35.It space
36Replace this occurrence and go on to the next one.
37.It \&.
38Replace this occurrence and don't change any more in this file (i.e., go
39on to the next file).
40.It \&,
41Tentatively replace this occurrence.
42The lines as they would look if the substitution were made are printed out.
43Then another character is read and it is used to decide the result as if
44the tentative replacement had not happened.
45.It n
46Don't change this one; just go on to the next one.
47.It \&^G
48Don't change this one or any others in this file, but instead simply go
49on to the next file.
50.It \&!
51Change the rest in this file without asking, then go on to the next
52file (at which point
53.Nm
54will start asking again).
55.It \&?
56Print out the current filename and ask again.
57.El
58.Pp
59The first two arguments to
60.Nm
61are always the string to replace and
62the string to replace it with.
63The options are as follows:
64.Bl -tag -width "-F filename" -compact -offset indent
65.It Fl w
66The search string is considered as a C symbol; it must be bounded by
67non-symbol characters.
68This option toggles.
69.Pf ( Sq w
70for
71.Sq word . )
72.It Fl \&!
73.It Fl go
74.It Fl noask
75Enter \&! mode automatically at the beginning of each file.
76.It Fl nogo
77.It Fl ask
78Negate
79.Fl go ,
80that is, ask as usual.
81.It Fl c Ns Ar N
82(Where
83.Ar N
84is a number.)
85Give
86.Ar N
87lines of context above and below the
88line with the match when prompting the user.
89.It Fl CA Ns Ar N
90(Where
91.Ar N
92is a number.)
93Give
94.Ar N
95lines of context above the line with the match when prompting the user.
96.It Fl CB Ns Ar N
97(Where
98.Ar N
99is a number.)
100Give
101.Ar N
102lines of context below the line with the match when prompting the user.
103.It Fl f Ar filename
104The
105.Ar filename
106argument is one of the files
107.Nm
108should perform substitutions in.
109.It Fl F Ar filename
110.Nm
111reads
112.Ar filename
113to get the names of files to perform substitutions in.
114The names should appear one to a line.
115.El
116.Pp
117The default amount of context is
118.Fl c2 ,
119that is, two lines above and two lines below the line with the match.
120.Pp
121Arguments not beginning with a
122.Fl \&
123sign in the options field are implicitly preceded by
124.Fl f .
125Thus,
126.Fl f
127is really needed only when the file name begins with a
128.Fl \&
129sign.
130.Pp
131.Nm
132reads its options in order and processes files as it gets them.
133This means, for example, that a
134.Fl go
135will affect only files named after the
136.Fl go .
137.Pp
138The most context you can get is ten lines each, above and below.
139.Pp
140.Ar str1
141is limited to 512 characters; there is no limit on the size of
142.Ar str2 .
143Neither one may contain a NUL.
144.Pp
145NULs in the file may cause
146.Nm
147to make various mistakes.
148.Pp
149If any other program modifies the file while
150.Nm
151is running, all
152bets are off.
153.Sh AUTHORS
154.An der Mouse Aq Mt mouse@rodents.montreal.qc.ca
155