33.10 Quick Globals from the Command Line with qsubst
Users at our office frequently have to make global changes across multiple files. For that purpose we encourage them to use sed (34.24 ) ; but sed syntax is tricky for new users (or even some experienced users!).
You'll be prompted with each line to be changed, in context. That is, the line containing the string will be surrounded by both the previous and the next lines in the file. The string to be changed is underlined:
Unlike emacs, vi is available on every \o'U_'\o'n_'\o'i_'\o'x_' system. So you can think of vi as the
To approve the change, press the space bar.
You'll then be
prompted with the next occurrence in the file.
To refuse the
You can also have qsubst replace all occurrences without prompting, using the -noask command-line option:
Both files are edited without prompting.
qsubst is clearly not as powerful as sed . It doesn't understand regular expressions: you can only use qsubst to replace simple strings. But qsubst is clearly a useful tool for users who just want to make a simple global change without learning sed .
One word of warning about qsubst : if you interrupt qsubst midstream (e.g., using CTRL-c), your stty settings are likely to be garbled. If this happens, try the tips in article 42.4 to get your stty settings correct again.