Skip to content

sed: print the c text when a numeric, relative or step range ends - #617

Open
jayhemnani9910 wants to merge 1 commit into
uutils:mainfrom
jayhemnani9910:change-at-range-end
Open

jayhemnani9910 wants to merge 1 commit into
uutils:mainfrom
jayhemnani9910:change-at-range-end

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

With a range whose end is a line number, +N or ~N, c deletes the lines but never prints its text. GNU sed 4.9 vs main:

$ seq 6 | sed '2,4c\X'
GNU:  1 X 5 6
main: 1 5 6

The same for 2,+2c and 2,~4c; /re/,/re/c works. Related cases in the same code:

$ seq 6 | sed '2,4!c\X'             GNU: X 2 3 4 X X   main: 2 3 4 X
$ seq 3 | sed '2,5c\X'              GNU: 1             main: 1 X
$ seq 9 | sed '/2/,/3/c\X
6,8c\Y'                              GNU: 1 X 4 5 Y 9   main: 1 X 4 5 Y Y Y 9
$ printf 'a\na\na\na\nb\n' | sed '/a/,3d'   GNU: b     main: a b

applies only set last_address when a regex or $ ended the range, and never cleared it, so c either missed the end or printed on every later line; c also printed at the last input line of an unfinished range and skipped negated ranges. Now last_address is cleared for each command and set when a line, +N or ~N end is reached; the range closes on that line, so the next line can start it again (the /a/,3d case). c prints at the end of a range, and on every line of a negated one.

New tests test_change_command_prints_text_at_range_end and test_range_with_line_end_restarts_on_next_line fail on main. cargo test: 748 passed (746 on main plus the two), clippy and fmt clean. 26 scripts with c, d, p, n, N and blocks over numeric, relative, step and regex ranges give the same output as GNU sed 4.9 on three inputs.

Copilot AI balanced review requested due to automatic review settings October 24, 2026 07:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@codecov

codecov Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.91%. Comparing base (caef481) to head (3aa1c9a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #617      +/-   ##
==========================================
- Coverage   94.93%   94.91%   -0.03%     
==========================================
  Files          14       14              
  Lines        7292     7302      +10     
  Branches      434      436       +2     
==========================================
+ Hits         6923     6931       +8     
- Misses        368      370       +2     
  Partials        1        1              
Flag Coverage Δ
macos_latest 96.44% <100.00%> (-0.03%) ⬇️
ubuntu_latest 96.38% <100.00%> (-0.03%) ⬇️
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.

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.

2 participants