You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
n starts a new cycle instead of continuing with the next command #568
After reading the next input line, uutils sed's n command ends the current cycle. The new line is processed from the beginning of the script instead of continuing with the command after n.
GNU sed continues with the next command.
This was reproduced with GNU sed 4.10 and uutils sed built from cffecd15, both under LC_ALL=C.
For example, n;d should keep every other line:
$ printf'a\nb\nc\nd\n'| sed 'n;d'ac
$ printf'a\nb\nc\nd\n'| ./target/release/sed 'n;d'abcd
The example used in the GNU sed manual shows the same difference:
POSIX describes n as: "Write the pattern space to standard output if the default output has not been suppressed, and replace the pattern space with the next line of input, less its terminating <newline>. If no next line of input is available, the n command verb shall branch to the end of the script and quit without starting a new cycle."
The n branch in src/sed/processor.rs currently uses break, which ends the cycle. The adjacent N implementation already preserves the next command in context.input_action and resumes there after reading another line. The same mechanism can be used for n, replacing the pattern space instead of appending to it.
I have a patch for this. Because the control-flow change also exposes the existing #541, I wanted to confirm the approach before opening a PR.
Activity