# replace-all-string(3)

[Home] [Commands] [Variables] [Macro-Dev] [Glossary]

## NAME

replace-all-string - Replace string with new string in a list of files

## SYNOPSIS

n replace-all-string "from" "to" "files" ["grep-from"]

## DESCRIPTION

replace-all-string, similar to replace-string(2), replaces all occurrences of "from" to "to" in the given list of files without prompting the user.

The command finds all occurrences of "from" by calling the command grep(3) to search for string "from" in files "files". Thus all relevant edited files must be saved or grep may return the wrong line numbers. This is achieved by a call to save-some-buffers(2) which prompts the user to save any changed buffers one at a time.

Each occurrence of "from" is jumped to using get-next-line(2) and the string is replaced by the call:

    -1 replace-string "from" "to"

This replaces all occurrences of "from" to "to" on the current line only, hence the line numbers must be correct. This also means that the "from" search string must be correctly formatted for both grep and replace-string, unless bit 0x02 is set (see below).

The given argument n is a bit based flag which changes the default behavior described above. The bits have the following effect:-

0x01

Prompt before saving any changed buffer, enabled by default. If this bit is not set then any changed buffer is automatically saved before the grep is performed.

0x02

If set then a fourth argument "grep-from" must also be given. This string is used in place of the "from" string for the grep only.

## NOTES

replace-all-string is a macro defined in `search.emf`.

The grep command must be working before this command can function properly.

It is not recommended to use a "from" or "to" string which uses more that one line as the results may be unpredictable.

As the change is likely to be over several files a single call to undo(2) at the end of execution will not undo all the changes made. To undo all the changes made, use get-next-line(2) to loop through all the occurrences and call undo for each occurrence

## SEE ALSO

replace-string(2), save-some-buffers(2), grep(3), get-next-line(2), undo(2), query-replace-all-string(3), replace-all-pairs(3), search-forward(2).

(c) Copyright JASSPA 2009
Last Modified: 2009/08/29
Generated On: 2009/10/12

</HMTL>