Add new tail -n +N, head -n -N options (#2071)

Inspired by GNU head & tail, they match their behavior while supporting
the usual grouping operations.

Co-authored-by: John Kerl <kerl.john.r@gmail.com>
This commit is contained in:
Jakub Okoński 2026-06-21 16:34:16 +02:00 committed by GitHub
parent f17721a5e9
commit 690ce997eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 228 additions and 36 deletions

View file

@ -26,8 +26,15 @@ func Getoptify(inargs []string) []string {
// Example: 'mlr unsparsify --fill-with -99999'.
outargs = append(outargs, inarg)
} else {
for _, c := range inarg[1:] {
outargs = append(outargs, "-"+string(c))
rest := inarg[1:]
for i := 0; i < len(rest); i++ {
// Pass integers without a leading dash, so that negative integers can be represented.
// Example: `head -n 4` and head -n4` can be differentiated from `head -n -4`.
if rest[i] >= '0' && rest[i] <= '9' {
outargs = append(outargs, rest[i:])
break
}
outargs = append(outargs, "-"+string(rest[i]))
}
}
} else if splitRegex.MatchString(inarg) {