uutils / uutils/coreutils

`csplit` should always suppress lines based on line numbers

Open
#6,126 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

U - csplit
Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Description

csplit has multiple ways to split files: based on regex, line numbers and more. The examples in this issue use this file:

seq 1 50 > 50.txt

If we use multiple line numbers in the wrong order, we get an error (both in uutils and GNU):

> csplit 50.txt 20 10
csplit: line number '10' is smaller than preceding line number, 20

So far so good. But, if we use a regex first and then a line number that is smaller than the number of the line where the regex matched we get in trouble:

# GNU
> csplit 50.txt /10/ 5 --suppress-matched
18
0
117

# uutils
csplit 50.txt /10/ 5 --suppress-matched`
18
0
120

The reason is that we seem to make a distinction between the less than and the equal case to determine whether the line should bee suppressed, but GNU doesn't.

cc @BenWiederhake

Found in https://github.com/uutils/coreutils/pull/6114

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the csplit implementation and its handling of regex matches, line-number operands, and --suppress-matched. Reproduce the commands from the issue and inspect existing csplit tests if available. Done means the mixed regex and decreasing line-number case suppresses lines with the same behavior as GNU csplit.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.