Implement all/by-regex field selection (-a/-r) for mlr sub, gsub, and ssub (#1480)

* Code-dedupe `sub`, `gsub`, and `ssub` verbs

* More dedupe

* Start with -a

* Implement -r

* unit-test cases

* Windows command-line parsing
This commit is contained in:
John Kerl 2024-01-23 17:18:13 -05:00 committed by GitHub
parent 81d11365a0
commit e5ec9f67bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
42 changed files with 475 additions and 518 deletions

View file

@ -1 +0,0 @@
mlr --d2p --from test/input/abixy sub -f a,b e X

View file

@ -1,11 +0,0 @@
a b i x y
pan pan 1 0.34679014 0.72680286
Xks pan 2 0.75867996 0.52215111
wyX wyX 3 0.20460331 0.33831853
Xks wyX 4 0.38139939 0.13418874
wyX pan 5 0.57328892 0.86362447
zXe pan 6 0.52712616 0.49322129
Xks zXe 7 0.61178406 0.18788492
zXe wyX 8 0.59855401 0.97618139
hat wyX 9 0.03144188 0.74955076
pan wyX 10 0.50262601 0.95261836

View file

@ -1 +0,0 @@
mlr --d2p --from test/input/abixy gsub -f a,b e X

View file

@ -1,11 +0,0 @@
a b i x y
pan pan 1 0.34679014 0.72680286
Xks pan 2 0.75867996 0.52215111
wyX wyX 3 0.20460331 0.33831853
Xks wyX 4 0.38139939 0.13418874
wyX pan 5 0.57328892 0.86362447
zXX pan 6 0.52712616 0.49322129
Xks zXX 7 0.61178406 0.18788492
zXX wyX 8 0.59855401 0.97618139
hat wyX 9 0.03144188 0.74955076
pan wyX 10 0.50262601 0.95261836

View file

@ -1 +0,0 @@
mlr --d2p --from test/input/abixy sub -f a,b . X

View file

@ -1,11 +0,0 @@
a b i x y
Xan Xan 1 0.34679014 0.72680286
Xks Xan 2 0.75867996 0.52215111
Xye Xye 3 0.20460331 0.33831853
Xks Xye 4 0.38139939 0.13418874
Xye Xan 5 0.57328892 0.86362447
Xee Xan 6 0.52712616 0.49322129
Xks Xee 7 0.61178406 0.18788492
Xee Xye 8 0.59855401 0.97618139
Xat Xye 9 0.03144188 0.74955076
Xan Xye 10 0.50262601 0.95261836

View file

@ -1 +0,0 @@
mlr --d2p --from test/input/abixy ssub -f a,b e X

View file

@ -1,11 +0,0 @@
a b i x y
pan pan 1 0.34679014 0.72680286
Xks pan 2 0.75867996 0.52215111
wyX wyX 3 0.20460331 0.33831853
Xks wyX 4 0.38139939 0.13418874
wyX pan 5 0.57328892 0.86362447
zXe pan 6 0.52712616 0.49322129
Xks zXe 7 0.61178406 0.18788492
zXe wyX 8 0.59855401 0.97618139
hat wyX 9 0.03144188 0.74955076
pan wyX 10 0.50262601 0.95261836

View file

@ -0,0 +1 @@
mlr --c2p --from test/input/example.csv gsub -a l X

View file

@ -0,0 +1,11 @@
color shape flag k index quantity rate
yeXXow triangXe true 1 11 43.64980000 9.88700000
red square true 2 15 79.27780000 0.01300000
red circXe true 3 16 13.81030000 2.90100000
red square faXse 4 48 77.55420000 7.46700000
purpXe triangXe faXse 5 51 81.22900000 8.59100000
red square faXse 6 64 77.19910000 9.53100000
purpXe triangXe faXse 7 65 80.14050000 5.82400000
yeXXow circXe true 8 73 63.97850000 4.23700000
yeXXow circXe true 9 87 63.50580000 8.33500000
purpXe square faXse 10 91 72.37350000 8.24300000

View file

@ -0,0 +1 @@
mlr --c2p --from test/input/example.csv gsub -f color,shape,index l X

View file

@ -0,0 +1,11 @@
color shape flag k index quantity rate
yeXXow triangXe true 1 11 43.64980000 9.88700000
red square true 2 15 79.27780000 0.01300000
red circXe true 3 16 13.81030000 2.90100000
red square false 4 48 77.55420000 7.46700000
purpXe triangXe false 5 51 81.22900000 8.59100000
red square false 6 64 77.19910000 9.53100000
purpXe triangXe false 7 65 80.14050000 5.82400000
yeXXow circXe true 8 73 63.97850000 4.23700000
yeXXow circXe true 9 87 63.50580000 8.33500000
purpXe square false 10 91 72.37350000 8.24300000

View file

@ -0,0 +1 @@
mlr --c2p --from test/input/example.csv gsub -r -f '.*e' l X

View file

@ -0,0 +1,11 @@
color shape flag k index quantity rate
yellow triangXe true 1 11 43.64980000 9.88700000
red square true 2 15 79.27780000 0.01300000
red circXe true 3 16 13.81030000 2.90100000
red square false 4 48 77.55420000 7.46700000
purple triangXe false 5 51 81.22900000 8.59100000
red square false 6 64 77.19910000 9.53100000
purple triangXe false 7 65 80.14050000 5.82400000
yellow circXe true 8 73 63.97850000 4.23700000
yellow circXe true 9 87 63.50580000 8.33500000
purple square false 10 91 72.37350000 8.24300000

View file

@ -0,0 +1 @@
mlr --c2p --from test/input/example.csv ssub -r -f '.*e' l X

View file

@ -0,0 +1,11 @@
color shape flag k index quantity rate
yellow triangXe true 1 11 43.64980000 9.88700000
red square true 2 15 79.27780000 0.01300000
red circXe true 3 16 13.81030000 2.90100000
red square false 4 48 77.55420000 7.46700000
purple triangXe false 5 51 81.22900000 8.59100000
red square false 6 64 77.19910000 9.53100000
purple triangXe false 7 65 80.14050000 5.82400000
yellow circXe true 8 73 63.97850000 4.23700000
yellow circXe true 9 87 63.50580000 8.33500000
purple square false 10 91 72.37350000 8.24300000

View file

@ -0,0 +1 @@
mlr --c2p --from test/input/example.csv sub -r -f '.*e' l X

View file

@ -0,0 +1,11 @@
color shape flag k index quantity rate
yellow triangXe true 1 11 43.64980000 9.88700000
red square true 2 15 79.27780000 0.01300000
red circXe true 3 16 13.81030000 2.90100000
red square false 4 48 77.55420000 7.46700000
purple triangXe false 5 51 81.22900000 8.59100000
red square false 6 64 77.19910000 9.53100000
purple triangXe false 7 65 80.14050000 5.82400000
yellow circXe true 8 73 63.97850000 4.23700000
yellow circXe true 9 87 63.50580000 8.33500000
purple square false 10 91 72.37350000 8.24300000

View file

@ -0,0 +1 @@
mlr --c2p --from test/input/example.csv ssub -a l X

View file

@ -0,0 +1,11 @@
color shape flag k index quantity rate
yeXlow triangXe true 1 11 43.64980000 9.88700000
red square true 2 15 79.27780000 0.01300000
red circXe true 3 16 13.81030000 2.90100000
red square faXse 4 48 77.55420000 7.46700000
purpXe triangXe faXse 5 51 81.22900000 8.59100000
red square faXse 6 64 77.19910000 9.53100000
purpXe triangXe faXse 7 65 80.14050000 5.82400000
yeXlow circXe true 8 73 63.97850000 4.23700000
yeXlow circXe true 9 87 63.50580000 8.33500000
purpXe square faXse 10 91 72.37350000 8.24300000

View file

@ -0,0 +1 @@
mlr --c2p --from test/input/example.csv ssub -f color,shape,index l X

View file

@ -0,0 +1,11 @@
color shape flag k index quantity rate
yeXlow triangXe true 1 11 43.64980000 9.88700000
red square true 2 15 79.27780000 0.01300000
red circXe true 3 16 13.81030000 2.90100000
red square false 4 48 77.55420000 7.46700000
purpXe triangXe false 5 51 81.22900000 8.59100000
red square false 6 64 77.19910000 9.53100000
purpXe triangXe false 7 65 80.14050000 5.82400000
yeXlow circXe true 8 73 63.97850000 4.23700000
yeXlow circXe true 9 87 63.50580000 8.33500000
purpXe square false 10 91 72.37350000 8.24300000

View file

@ -0,0 +1 @@
mlr --c2p --from test/input/example.csv sub -a l X

View file

@ -0,0 +1,11 @@
color shape flag k index quantity rate
yeXlow triangXe true 1 11 43.64980000 9.88700000
red square true 2 15 79.27780000 0.01300000
red circXe true 3 16 13.81030000 2.90100000
red square faXse 4 48 77.55420000 7.46700000
purpXe triangXe faXse 5 51 81.22900000 8.59100000
red square faXse 6 64 77.19910000 9.53100000
purpXe triangXe faXse 7 65 80.14050000 5.82400000
yeXlow circXe true 8 73 63.97850000 4.23700000
yeXlow circXe true 9 87 63.50580000 8.33500000
purpXe square faXse 10 91 72.37350000 8.24300000

View file

@ -0,0 +1 @@
mlr --c2p --from test/input/example.csv sub -f a,b l X

View file

@ -0,0 +1,11 @@
color shape flag k index quantity rate
yellow triangle true 1 11 43.64980000 9.88700000
red square true 2 15 79.27780000 0.01300000
red circle true 3 16 13.81030000 2.90100000
red square false 4 48 77.55420000 7.46700000
purple triangle false 5 51 81.22900000 8.59100000
red square false 6 64 77.19910000 9.53100000
purple triangle false 7 65 80.14050000 5.82400000
yellow circle true 8 73 63.97850000 4.23700000
yellow circle true 9 87 63.50580000 8.33500000
purple square false 10 91 72.37350000 8.24300000

View file

@ -0,0 +1 @@
mlr --c2p --from test/input/example.csv sub -f color,shape,index l X

View file

@ -0,0 +1,11 @@
color shape flag k index quantity rate
yeXlow triangXe true 1 11 43.64980000 9.88700000
red square true 2 15 79.27780000 0.01300000
red circXe true 3 16 13.81030000 2.90100000
red square false 4 48 77.55420000 7.46700000
purpXe triangXe false 5 51 81.22900000 8.59100000
red square false 6 64 77.19910000 9.53100000
purpXe triangXe false 7 65 80.14050000 5.82400000
yeXlow circXe true 8 73 63.97850000 4.23700000
yeXlow circXe true 9 87 63.50580000 8.33500000
purpXe square false 10 91 72.37350000 8.24300000