Skip to content

sed: continue with the next command after n instead of starting a new cycle - #592

Merged
sylvestre merged 3 commits into
uutils:mainfrom
DePasqualeOrg:fix-n-command
Oct 3, 2026
Merged

sylvestre merged 3 commits into
uutils:mainfrom
DePasqualeOrg:fix-n-command

Conversation

@DePasqualeOrg

@DePasqualeOrg DePasqualeOrg commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Claude Code and Codex flagged this gap during my work with this project. The changes here have gone through extensive automated review. I'm happy to make changes as needed or close this PR and maintain it as a private patch if it doesn't meet your standards.


Fixes #568.

GNU sed's n prints the pattern space unless -n is given, writes any text queued by a, r or R, replaces the pattern space with the next line of input, and continues with the command after n. In uutils sed, n ends the cycle instead, so the next line starts the script from the top. For example, printf '1\n2\n3\n4\n' | sed 'n;d' prints all four lines, while GNU sed prints 1 and 3.

This PR handles n the way N already works: it records the command to continue from, and when the next line has been read, processing resumes there with that line as the pattern space. If there is no next line, sed stops without running the remaining commands, as GNU sed does. Without -s, n reads the first line of the next file; with -s or -i, each file starts at the top of the script.

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 65 / PASSED: 18 / FAILED: 39 / SKIPPED: 8
  Reference: TOTAL: 65 / PASSED: 17 / FAILED: 40 / SKIPPED: 8

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + distrib

@codecov

codecov Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.82%. Comparing base (21ffff7) to head (e792047).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #592   +/-   ##
=======================================
  Coverage   94.82%   94.82%           
=======================================
  Files          14       14           
  Lines        7203     7212    +9     
  Branches      424      428    +4     
=======================================
+ Hits         6830     6839    +9     
  Misses        372      372           
  Partials        1        1           
Flag Coverage Δ
macos_latest 96.36% <100.00%> (+<0.01%) ⬆️
ubuntu_latest 96.30% <100.00%> (+<0.01%) ⬆️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 65 / PASSED: 18 / FAILED: 39 / SKIPPED: 8
  Reference: TOTAL: 65 / PASSED: 17 / FAILED: 40 / SKIPPED: 8

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + distrib

Comment thread tests/by-util/test_sed.rs
.succeeds()
.stdout_is("a\nXline one\nline two\n");
new_ucmd!()
.args(&["-s", "n;s/^/X/", "-", "input/two-lines.txt"])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add an n case to in_place_edit_separate too, the description mentions -i but nothing tests it

Comment thread src/sed/command.rs Outdated
pub prepend: Vec<u8>,
/// Data to prepend to the read contents (`N`), or `None` to replace
/// the pattern space with them (`n`)
pub prepend: Option<Vec<u8>>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None meaning "replace" is a bit implicit, maybe a small enum would read better? not blocking

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 65 / PASSED: 18 / FAILED: 39 / SKIPPED: 8
  Reference: TOTAL: 65 / PASSED: 17 / FAILED: 40 / SKIPPED: 8

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + distrib

@sylvestre
sylvestre merged commit 3676eac into uutils:main Oct 3, 2026
31 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

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.

n starts a new cycle instead of continuing with the next command

2 participants