mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-17 16:38:54 +00:00
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:
parent
f17721a5e9
commit
690ce997eb
29 changed files with 228 additions and 36 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue