# info > INPLACE

---
type: CommandReference
command: inplace
mode: man
section: 3am
source: man-pages
---

## Quick Reference
- `gawk -i inplace 'program' files...` — run AWK program, overwriting input files with output
- `gawk -i inplace -f script.awk files...` — use an AWK script file for in-place editing
- `gawk -i inplace -v inplace::suffix=.bak '{ ... }' files...` — keep original files as `file.bak`
- `gawk -i inplace -v inplace::enable=0 file1 file2 -v inplace::enable=1 file3` — edit only `file3`, treat `file1` and `file2` normally

## Name
inplace - emulate sed/perl/ruby in-place editing

## Synopsis
shell
gawk -i inplace [-v inplace::suffix=SUFFIX] [-v inplace::enable=0|1] 'program' files...
## Options
The extension is controlled by AWK variables set via `-v` or in a `BEGIN` rule.

- `inplace::suffix` — suffix appended to the original filename for backup. If set, the original file is renamed to `FILENAME + suffix` and the output becomes the new file. Default: no backup (original replaced directly).
- `INPLACE_SUFFIX` — backward‑compatible alias for `inplace::suffix`. Used only if `inplace::suffix` is not set.
- `inplace::enable` — set to `0` to disable in‑place editing for subsequent files; set to `1` to re‑enable. Files processed while disabled are handled normally (output goes to standard output or as directed by the script).

## Description
The `inplace` extension provides two internal functions (`inplace_begin()` and `inplace_end()`) invoked automatically by the `inplace.awk` wrapper. Each file named on the command line is replaced with new content after AWK processing. Ownership and permissions of the original file are preserved when possible, but ACLs are **not** copied. If the AWK program terminates abruptly (e.g., due to an unhandled signal), a temporary file may be left behind.

## Examples
shell
# Replace all occurrences of 'foo' with 'bar' in every file
gawk -i inplace '{ gsub(/foo/, "bar"); print }' *.txt

# Use an external script file for complex processing
gawk -i inplace -f my_script.awk data.csv

# Keep a backup copy of the original file
gawk -i inplace -v inplace::suffix=.orig '{ print toupper($0) }' file.txt

# Disable in-place editing for the first two files, enable for the third
gawk -i inplace -v inplace::enable=0 file1 file2 -v inplace::enable=1 file3
## See Also
- [filefuncs(3am)](http://localhost/phpMan.php/man/filefuncs/3am/markdown)
- [fnmatch(3am)](http://localhost/phpMan.php/man/fnmatch/3am/markdown)
- [fork(3am)](http://localhost/phpMan.php/man/fork/3am/markdown)
- [ordchr(3am)](http://localhost/phpMan.php/man/ordchr/3am/markdown)
- [readdir(3am)](http://localhost/phpMan.php/man/readdir/3am/markdown)
- [readfile(3am)](http://localhost/phpMan.php/man/readfile/3am/markdown)
- [revoutput(3am)](http://localhost/phpMan.php/man/revoutput/3am/markdown)
- [rwarray(3am)](http://localhost/phpMan.php/man/rwarray/3am/markdown)