Skip to content

One-liners read files and edit them in place: operands after -n/-p code, filename, fnr and -i (D222, #958) - #3460

Merged
ehartford merged 3 commits into
mainfrom
oneliner-files
Nov 19, 2026
Merged

ehartford merged 3 commits into
mainfrom
oneliner-files

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Closes #958. Delegated (D98; D222 records the brief): a CLI surface, easy to reverse, prediction 80%.

with -n 'if fnr == 1: print(filename)' a.txt b.txt        # awk with files
with -e 'var n = 0' -n 'n += 1' -e 'print(n)' *.log        # count lines across files
with -p -i 'line = line.replace("old", "new")' notes.txt   # sed -i
  • Input files. Operands after -n or -p code are read in order in place of stdin. The one-liner's source is the flag's value, so an operand is never the source; -e alone still refuses one.
  • filename and fnr are bound when the code names them and does not declare its own, as last is. nr counts across all files; last is the final line of the last file.
  • -i with -p writes each file back through a sibling (<file>.with-tmp) and a rename; a file that ended without a newline still does. -p -i CODE and -i -p CODE are both accepted. -i with -n, with -e alone or with no file is refused.
  • A file that cannot be read stops the program: an error and exit 2.

Spec v7.68 (§18.5b.3 and the one-liner document, marked delegated); the flag inventory and the flag table list -i; the instructions' parity table and the gap list are brought up to date. Eight harness cases.

Battery green on the branch tip.

@ehartford
ehartford merged commit 0b671ad into main Nov 19, 2026
@ehartford
ehartford deleted the oneliner-files branch November 19, 2026 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

one-liners: no file operands (awk/sed FILE…), no FILENAME/fnr, no -i in-place edit — §18.5b forbids the combination

1 participant