Skip to content

Fix grep -wo, head --silent/-n -N, cat -E CRLF#19

Open
kelp wants to merge 1 commit intomainfrom
fix-grep-head-cat-audit-tests
Open

Fix grep -wo, head --silent/-n -N, cat -E CRLF#19
kelp wants to merge 1 commit intomainfrom
fix-grep-head-cat-audit-tests

Conversation

@kelp
Copy link
Copy Markdown
Owner

@kelp kelp commented Mar 30, 2026

Summary

  • grep: Fix -wo to output only the matched word, not boundary characters. When -w wraps the regex pattern with boundary groups, match positions now come from submatch group 2 (the word) instead of group 0 (the full match including boundary chars).
  • head: Add --silent as alias for --quiet (matches GNU coreutils). Implement -n -N negative suffix to output all but the last N lines. Fix expandObsoleteArgs to not misinterpret -3 as obsolete -NUM syntax when it follows -n/-c.
  • cat: When -E is active without -v, convert trailing \r before \n to ^M$ to match GNU cat behavior.

Test plan

  • All 4 grep -wo audit tests pass (G-03 variants)
  • head --silent alias test passes
  • head -n -3 negative count test passes
  • cat -E CRLF tests pass (single line, mid-line CR preserved, multiple CRLF lines)
  • No regressions in grep, head, or cat test suites

grep: When -w wraps the pattern with boundary groups, use
submatch group 2 (the word) for -o output positions instead
of group 0 (which includes boundary characters).

head: Add --silent as alias for --quiet using the same
pattern as readlink. Parse -n value as string to support
negative counts (-n -3 = all but last 3 lines). Fix
expandObsoleteArgs to not expand -NUM when it follows -n/-c.

cat: When -E is active without -v, convert trailing \r
before \n to ^M$ to match GNU cat behavior.
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.

1 participant