Bug
The GNU W command — write only the first line of the pattern
space (up to the first embedded \n) to a file — is not implemented.
It is the partial-write counterpart to w.
Reproduction
$ printf "abc\ndef\n" | /usr/bin/sed -n 'N;W/dev/stdout'
abc
$ printf "abc\ndef\n" | ./target/release/sed -n 'N;W/dev/stdout'
sed: <script argument 1>:1:3: error: invalid command code `W'
What it should do
From the GNU manual:
W FILENAME Write to the given filename the portion of the pattern
space up to the first newline.
Same filename-parsing as w. Opens the file once, appends each
invocation. Honors --sandbox rejection (already plumbed for w).
Suspected place to add it
src/sed/compiler.rs:1276 — get_cmd_spec. Add:
'W' => Ok(CommandSpec {
n_addr: 2,
handler: compile_write_file_command, // same parser as 'w'
}),
In the execution path (search for the w case in processor.rs),
write only the bytes up to the first \n instead of the whole pattern
space.
Affected GNU testsuite tests
missing-filename, sandbox (both also test W rejection paths).
Bug
The GNU
Wcommand — write only the first line of the patternspace (up to the first embedded
\n) to a file — is not implemented.It is the partial-write counterpart to
w.Reproduction
What it should do
From the GNU manual:
Same filename-parsing as
w. Opens the file once, appends eachinvocation. Honors
--sandboxrejection (already plumbed forw).Suspected place to add it
src/sed/compiler.rs:1276—get_cmd_spec. Add:In the execution path (search for the
wcase inprocessor.rs),write only the bytes up to the first
\ninstead of the whole patternspace.
Affected GNU testsuite tests
missing-filename,sandbox(both also testWrejection paths).