mirror of
https://github.com/johnkerl/miller.git
synced 2026-01-23 02:14:13 +00:00
New leftpad and rightpad DSL functions (#1205)
* Initial code for `leftpad` and `rightpad` functions * typofix, and test cases * doc-gen * windows UT
This commit is contained in:
parent
58ef380f98
commit
ee0ac3d7bb
48 changed files with 360 additions and 51 deletions
|
|
@ -213,17 +213,17 @@ MILLER(1) MILLER(1)
|
|||
invqnorm is_absent is_array is_bool is_boolean is_empty is_empty_map is_error
|
||||
is_float is_int is_map is_nan is_nonempty_map is_not_array is_not_empty
|
||||
is_not_map is_not_null is_null is_numeric is_present is_string joink joinkv
|
||||
joinv json_parse json_stringify latin1_to_utf8 leafcount length localtime2gmt
|
||||
localtime2sec log log10 log1p logifit lstrip madd mapdiff mapexcept mapselect
|
||||
mapsum max md5 mexp min mmul msub os pow qnorm reduce regextract
|
||||
regextract_or_else round roundm rstrip sec2dhms sec2gmt sec2gmtdate sec2hms
|
||||
sec2localdate sec2localtime select sgn sha1 sha256 sha512 sin sinh sort splita
|
||||
splitax splitkv splitkvx splitnv splitnvx sqrt ssub strftime strftime_local
|
||||
string strip strlen strptime strptime_local sub substr substr0 substr1 system
|
||||
systime systimeint tan tanh tolower toupper truncate typeof unflatten unformat
|
||||
unformatx uptime urand urand32 urandelement urandint urandrange utf8_to_latin1
|
||||
version ! != !=~ % & && * ** + - . .* .+ .- ./ / // < << <= <=> == =~ > >= >>
|
||||
>>> ?: ?? ??? ^ ^^ | || ~
|
||||
joinv json_parse json_stringify latin1_to_utf8 leafcount leftpad length
|
||||
localtime2gmt localtime2sec log log10 log1p logifit lstrip madd mapdiff
|
||||
mapexcept mapselect mapsum max md5 mexp min mmul msub os pow qnorm reduce
|
||||
regextract regextract_or_else rightpad round roundm rstrip sec2dhms sec2gmt
|
||||
sec2gmtdate sec2hms sec2localdate sec2localtime select sgn sha1 sha256 sha512
|
||||
sin sinh sort splita splitax splitkv splitkvx splitnv splitnvx sqrt ssub
|
||||
strftime strftime_local string strip strlen strptime strptime_local sub substr
|
||||
substr0 substr1 system systime systimeint tan tanh tolower toupper truncate
|
||||
typeof unflatten unformat unformatx uptime urand urand32 urandelement urandint
|
||||
urandrange utf8_to_latin1 version ! != !=~ % & && * ** + - . .* .+ .- ./ / //
|
||||
< << <= <=> == =~ > >= >> >>> ?: ?? ??? ^ ^^ | || ~
|
||||
|
||||
1mCOMMENTS-IN-DATA FLAGS0m
|
||||
Miller lets you put comments in your data, such as
|
||||
|
|
@ -2459,6 +2459,13 @@ MILLER(1) MILLER(1)
|
|||
1mleafcount0m
|
||||
(class=collections #args=1) Counts total number of terminal values in map/array. For single-level map/array, same as length.
|
||||
|
||||
1mleftpad0m
|
||||
(class=string #args=3) Left-pads first argument to at most the specified length (second, integer argument) using specified pad value (third, string argument). If the first argument is not a string, it will be stringified first.
|
||||
Examples:
|
||||
leftpad("abcdefg", 10 , "*") gives "***abcdefg".
|
||||
leftpad("abcdefg", 10 , "XY") gives "XYabcdefg".
|
||||
leftpad("1234567", 10 , "0") gives "0001234567".
|
||||
|
||||
1mlength0m
|
||||
(class=collections #args=1) Counts number of top-level entries in array/map. Scalars have length 1.
|
||||
|
||||
|
|
@ -2549,6 +2556,13 @@ MILLER(1) MILLER(1)
|
|||
regextract_or_else("index ab09 file", "[a-z][a-z][0-9][0-9]", "nonesuch") gives "ab09"
|
||||
regextract_or_else("index a999 file", "[a-z][a-z][0-9][0-9]", "nonesuch") gives "nonesuch"
|
||||
|
||||
1mrightpad0m
|
||||
(class=string #args=3) Right-pads first argument to at most the specified length (second, integer argument) using specified pad value (third, string argument). If the first argument is not a string, it will be stringified first.
|
||||
Examples:
|
||||
rightpad("abcdefg", 10 , "*") gives "abcdefg***".
|
||||
rightpad("abcdefg", 10 , "XY") gives "abcdefgXY".
|
||||
rightpad("1234567", 10 , "0") gives "1234567000".
|
||||
|
||||
1mround0m
|
||||
(class=math #args=1) Round to nearest integer.
|
||||
|
||||
|
|
@ -3297,5 +3311,5 @@ MILLER(1) MILLER(1)
|
|||
|
||||
|
||||
|
||||
2023-01-28 MILLER(1)
|
||||
2023-02-26 MILLER(1)
|
||||
</pre>
|
||||
|
|
|
|||
|
|
@ -192,17 +192,17 @@ MILLER(1) MILLER(1)
|
|||
invqnorm is_absent is_array is_bool is_boolean is_empty is_empty_map is_error
|
||||
is_float is_int is_map is_nan is_nonempty_map is_not_array is_not_empty
|
||||
is_not_map is_not_null is_null is_numeric is_present is_string joink joinkv
|
||||
joinv json_parse json_stringify latin1_to_utf8 leafcount length localtime2gmt
|
||||
localtime2sec log log10 log1p logifit lstrip madd mapdiff mapexcept mapselect
|
||||
mapsum max md5 mexp min mmul msub os pow qnorm reduce regextract
|
||||
regextract_or_else round roundm rstrip sec2dhms sec2gmt sec2gmtdate sec2hms
|
||||
sec2localdate sec2localtime select sgn sha1 sha256 sha512 sin sinh sort splita
|
||||
splitax splitkv splitkvx splitnv splitnvx sqrt ssub strftime strftime_local
|
||||
string strip strlen strptime strptime_local sub substr substr0 substr1 system
|
||||
systime systimeint tan tanh tolower toupper truncate typeof unflatten unformat
|
||||
unformatx uptime urand urand32 urandelement urandint urandrange utf8_to_latin1
|
||||
version ! != !=~ % & && * ** + - . .* .+ .- ./ / // < << <= <=> == =~ > >= >>
|
||||
>>> ?: ?? ??? ^ ^^ | || ~
|
||||
joinv json_parse json_stringify latin1_to_utf8 leafcount leftpad length
|
||||
localtime2gmt localtime2sec log log10 log1p logifit lstrip madd mapdiff
|
||||
mapexcept mapselect mapsum max md5 mexp min mmul msub os pow qnorm reduce
|
||||
regextract regextract_or_else rightpad round roundm rstrip sec2dhms sec2gmt
|
||||
sec2gmtdate sec2hms sec2localdate sec2localtime select sgn sha1 sha256 sha512
|
||||
sin sinh sort splita splitax splitkv splitkvx splitnv splitnvx sqrt ssub
|
||||
strftime strftime_local string strip strlen strptime strptime_local sub substr
|
||||
substr0 substr1 system systime systimeint tan tanh tolower toupper truncate
|
||||
typeof unflatten unformat unformatx uptime urand urand32 urandelement urandint
|
||||
urandrange utf8_to_latin1 version ! != !=~ % & && * ** + - . .* .+ .- ./ / //
|
||||
< << <= <=> == =~ > >= >> >>> ?: ?? ??? ^ ^^ | || ~
|
||||
|
||||
1mCOMMENTS-IN-DATA FLAGS0m
|
||||
Miller lets you put comments in your data, such as
|
||||
|
|
@ -2438,6 +2438,13 @@ MILLER(1) MILLER(1)
|
|||
1mleafcount0m
|
||||
(class=collections #args=1) Counts total number of terminal values in map/array. For single-level map/array, same as length.
|
||||
|
||||
1mleftpad0m
|
||||
(class=string #args=3) Left-pads first argument to at most the specified length (second, integer argument) using specified pad value (third, string argument). If the first argument is not a string, it will be stringified first.
|
||||
Examples:
|
||||
leftpad("abcdefg", 10 , "*") gives "***abcdefg".
|
||||
leftpad("abcdefg", 10 , "XY") gives "XYabcdefg".
|
||||
leftpad("1234567", 10 , "0") gives "0001234567".
|
||||
|
||||
1mlength0m
|
||||
(class=collections #args=1) Counts number of top-level entries in array/map. Scalars have length 1.
|
||||
|
||||
|
|
@ -2528,6 +2535,13 @@ MILLER(1) MILLER(1)
|
|||
regextract_or_else("index ab09 file", "[a-z][a-z][0-9][0-9]", "nonesuch") gives "ab09"
|
||||
regextract_or_else("index a999 file", "[a-z][a-z][0-9][0-9]", "nonesuch") gives "nonesuch"
|
||||
|
||||
1mrightpad0m
|
||||
(class=string #args=3) Right-pads first argument to at most the specified length (second, integer argument) using specified pad value (third, string argument). If the first argument is not a string, it will be stringified first.
|
||||
Examples:
|
||||
rightpad("abcdefg", 10 , "*") gives "abcdefg***".
|
||||
rightpad("abcdefg", 10 , "XY") gives "abcdefgXY".
|
||||
rightpad("1234567", 10 , "0") gives "1234567000".
|
||||
|
||||
1mround0m
|
||||
(class=math #args=1) Round to nearest integer.
|
||||
|
||||
|
|
@ -3276,4 +3290,4 @@ MILLER(1) MILLER(1)
|
|||
|
||||
|
||||
|
||||
2023-01-28 MILLER(1)
|
||||
2023-02-26 MILLER(1)
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ is 2. Unary operators such as `!` and `~` show argument-count of 1; the ternary
|
|||
* [**Hashing functions**](#hashing-functions): [md5](#md5), [sha1](#sha1), [sha256](#sha256), [sha512](#sha512).
|
||||
* [**Higher-order-functions functions**](#higher-order-functions-functions): [any](#any), [apply](#apply), [every](#every), [fold](#fold), [reduce](#reduce), [select](#select), [sort](#sort).
|
||||
* [**Math functions**](#math-functions): [abs](#abs), [acos](#acos), [acosh](#acosh), [asin](#asin), [asinh](#asinh), [atan](#atan), [atan2](#atan2), [atanh](#atanh), [cbrt](#cbrt), [ceil](#ceil), [cos](#cos), [cosh](#cosh), [erf](#erf), [erfc](#erfc), [exp](#exp), [expm1](#expm1), [floor](#floor), [invqnorm](#invqnorm), [log](#log), [log10](#log10), [log1p](#log1p), [logifit](#logifit), [max](#max), [min](#min), [qnorm](#qnorm), [round](#round), [roundm](#roundm), [sgn](#sgn), [sin](#sin), [sinh](#sinh), [sqrt](#sqrt), [tan](#tan), [tanh](#tanh), [urand](#urand), [urand32](#urand32), [urandelement](#urandelement), [urandint](#urandint), [urandrange](#urandrange).
|
||||
* [**String functions**](#string-functions): [capitalize](#capitalize), [clean_whitespace](#clean_whitespace), [collapse_whitespace](#collapse_whitespace), [format](#format), [gssub](#gssub), [gsub](#gsub), [latin1_to_utf8](#latin1_to_utf8), [lstrip](#lstrip), [regextract](#regextract), [regextract_or_else](#regextract_or_else), [rstrip](#rstrip), [ssub](#ssub), [strip](#strip), [strlen](#strlen), [sub](#sub), [substr](#substr), [substr0](#substr0), [substr1](#substr1), [tolower](#tolower), [toupper](#toupper), [truncate](#truncate), [unformat](#unformat), [unformatx](#unformatx), [utf8_to_latin1](#utf8_to_latin1), [\.](#dot).
|
||||
* [**String functions**](#string-functions): [capitalize](#capitalize), [clean_whitespace](#clean_whitespace), [collapse_whitespace](#collapse_whitespace), [format](#format), [gssub](#gssub), [gsub](#gsub), [latin1_to_utf8](#latin1_to_utf8), [leftpad](#leftpad), [lstrip](#lstrip), [regextract](#regextract), [regextract_or_else](#regextract_or_else), [rightpad](#rightpad), [rstrip](#rstrip), [ssub](#ssub), [strip](#strip), [strlen](#strlen), [sub](#sub), [substr](#substr), [substr0](#substr0), [substr1](#substr1), [tolower](#tolower), [toupper](#toupper), [truncate](#truncate), [unformat](#unformat), [unformatx](#unformatx), [utf8_to_latin1](#utf8_to_latin1), [\.](#dot).
|
||||
* [**System functions**](#system-functions): [exec](#exec), [hostname](#hostname), [os](#os), [system](#system), [version](#version).
|
||||
* [**Time functions**](#time-functions): [dhms2fsec](#dhms2fsec), [dhms2sec](#dhms2sec), [fsec2dhms](#fsec2dhms), [fsec2hms](#fsec2hms), [gmt2localtime](#gmt2localtime), [gmt2sec](#gmt2sec), [hms2fsec](#hms2fsec), [hms2sec](#hms2sec), [localtime2gmt](#localtime2gmt), [localtime2sec](#localtime2sec), [sec2dhms](#sec2dhms), [sec2gmt](#sec2gmt), [sec2gmtdate](#sec2gmtdate), [sec2hms](#sec2hms), [sec2localdate](#sec2localdate), [sec2localtime](#sec2localtime), [strftime](#strftime), [strftime_local](#strftime_local), [strptime](#strptime), [strptime_local](#strptime_local), [systime](#systime), [systimeint](#systimeint), [uptime](#uptime).
|
||||
* [**Typing functions**](#typing-functions): [asserting_absent](#asserting_absent), [asserting_array](#asserting_array), [asserting_bool](#asserting_bool), [asserting_boolean](#asserting_boolean), [asserting_empty](#asserting_empty), [asserting_empty_map](#asserting_empty_map), [asserting_error](#asserting_error), [asserting_float](#asserting_float), [asserting_int](#asserting_int), [asserting_map](#asserting_map), [asserting_nonempty_map](#asserting_nonempty_map), [asserting_not_array](#asserting_not_array), [asserting_not_empty](#asserting_not_empty), [asserting_not_map](#asserting_not_map), [asserting_not_null](#asserting_not_null), [asserting_null](#asserting_null), [asserting_numeric](#asserting_numeric), [asserting_present](#asserting_present), [asserting_string](#asserting_string), [is_absent](#is_absent), [is_array](#is_array), [is_bool](#is_bool), [is_boolean](#is_boolean), [is_empty](#is_empty), [is_empty_map](#is_empty_map), [is_error](#is_error), [is_float](#is_float), [is_int](#is_int), [is_map](#is_map), [is_nan](#is_nan), [is_nonempty_map](#is_nonempty_map), [is_not_array](#is_not_array), [is_not_empty](#is_not_empty), [is_not_map](#is_not_map), [is_not_null](#is_not_null), [is_null](#is_null), [is_numeric](#is_numeric), [is_present](#is_present), [is_string](#is_string), [typeof](#typeof).
|
||||
|
|
@ -1024,6 +1024,16 @@ $* = latin1_to_utf8($*)
|
|||
</pre>
|
||||
|
||||
|
||||
### leftpad
|
||||
<pre class="pre-non-highlight-non-pair">
|
||||
leftpad (class=string #args=3) Left-pads first argument to at most the specified length (second, integer argument) using specified pad value (third, string argument). If the first argument is not a string, it will be stringified first.
|
||||
Examples:
|
||||
leftpad("abcdefg", 10 , "*") gives "***abcdefg".
|
||||
leftpad("abcdefg", 10 , "XY") gives "XYabcdefg".
|
||||
leftpad("1234567", 10 , "0") gives "0001234567".
|
||||
</pre>
|
||||
|
||||
|
||||
### lstrip
|
||||
<pre class="pre-non-highlight-non-pair">
|
||||
lstrip (class=string #args=1) Strip leading whitespace from string.
|
||||
|
|
@ -1048,6 +1058,16 @@ regextract_or_else("index a999 file", "[a-z][a-z][0-9][0-9]", "nonesuch") gives
|
|||
</pre>
|
||||
|
||||
|
||||
### rightpad
|
||||
<pre class="pre-non-highlight-non-pair">
|
||||
rightpad (class=string #args=3) Right-pads first argument to at most the specified length (second, integer argument) using specified pad value (third, string argument). If the first argument is not a string, it will be stringified first.
|
||||
Examples:
|
||||
rightpad("abcdefg", 10 , "*") gives "abcdefg***".
|
||||
rightpad("abcdefg", 10 , "XY") gives "abcdefgXY".
|
||||
rightpad("1234567", 10 , "0") gives "1234567000".
|
||||
</pre>
|
||||
|
||||
|
||||
### rstrip
|
||||
<pre class="pre-non-highlight-non-pair">
|
||||
rstrip (class=string #args=1) Strip trailing whitespace from string.
|
||||
|
|
|
|||
|
|
@ -2264,7 +2264,8 @@ More example put expressions:
|
|||
'$new_field = $index**2; $qn = $quantity * $new_field'
|
||||
Regex-replacement:
|
||||
'$name = sub($name, "http.*com"i, "")'
|
||||
'if ($a =~ "([a-z]+)_([0-9]+)") { $b = "left_\1"; $c = "right_\2" }'
|
||||
Regex-capture:
|
||||
'if ($a =~ "([a-z]+)_([0-9]+)") { $b = "left_\1"; $c = "right_\2" }'
|
||||
Built-in variables:
|
||||
'$filename = FILENAME'
|
||||
Aggregations (use mlr put -q):
|
||||
|
|
|
|||
|
|
@ -154,6 +154,73 @@ func BIF_truncate(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
}
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
func BIF_leftpad(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
if input1.IsErrorOrAbsent() {
|
||||
return input1
|
||||
}
|
||||
if input2.IsErrorOrAbsent() {
|
||||
return input2
|
||||
}
|
||||
if input3.IsErrorOrAbsent() {
|
||||
return input3
|
||||
}
|
||||
|
||||
if !input2.IsInt() {
|
||||
return mlrval.ERROR
|
||||
}
|
||||
|
||||
inputString := input1.String()
|
||||
padString := input3.String()
|
||||
|
||||
inputLength := lib.UTF8Strlen(inputString)
|
||||
padLength := lib.UTF8Strlen(padString)
|
||||
targetLength := input2.AcquireIntValue()
|
||||
outputLength := inputLength
|
||||
|
||||
var buffer bytes.Buffer
|
||||
for outputLength+padLength <= targetLength {
|
||||
buffer.WriteString(padString)
|
||||
outputLength += padLength
|
||||
}
|
||||
buffer.WriteString(inputString)
|
||||
|
||||
return mlrval.FromString(buffer.String())
|
||||
}
|
||||
|
||||
func BIF_rightpad(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
if input1.IsErrorOrAbsent() {
|
||||
return input1
|
||||
}
|
||||
if input2.IsErrorOrAbsent() {
|
||||
return input2
|
||||
}
|
||||
if input3.IsErrorOrAbsent() {
|
||||
return input3
|
||||
}
|
||||
|
||||
if !input2.IsInt() {
|
||||
return mlrval.ERROR
|
||||
}
|
||||
|
||||
inputString := input1.String()
|
||||
padString := input3.String()
|
||||
|
||||
inputLength := lib.UTF8Strlen(inputString)
|
||||
padLength := lib.UTF8Strlen(padString)
|
||||
targetLength := input2.AcquireIntValue()
|
||||
outputLength := inputLength
|
||||
|
||||
var buffer bytes.Buffer
|
||||
buffer.WriteString(inputString)
|
||||
for outputLength+padLength <= targetLength {
|
||||
buffer.WriteString(padString)
|
||||
outputLength += padLength
|
||||
}
|
||||
|
||||
return mlrval.FromString(buffer.String())
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
func BIF_lstrip(input1 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
if input1.IsString() {
|
||||
|
|
|
|||
|
|
@ -560,6 +560,29 @@ Arrays are new in Miller 6; the substr function is older.`,
|
|||
binaryFunc: bifs.BIF_truncate,
|
||||
},
|
||||
|
||||
{
|
||||
name: "leftpad",
|
||||
class: FUNC_CLASS_STRING,
|
||||
help: `Left-pads first argument to at most the specified length (second, integer argument) using specified pad value (third, string argument). If the first argument is not a string, it will be stringified first.`,
|
||||
ternaryFunc: bifs.BIF_leftpad,
|
||||
examples: []string{
|
||||
`leftpad("abcdefg", 10 , "*") gives "***abcdefg".`,
|
||||
`leftpad("abcdefg", 10 , "XY") gives "XYabcdefg".`,
|
||||
`leftpad("1234567", 10 , "0") gives "0001234567".`,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "rightpad",
|
||||
class: FUNC_CLASS_STRING,
|
||||
help: `Right-pads first argument to at most the specified length (second, integer argument) using specified pad value (third, string argument). If the first argument is not a string, it will be stringified first.`,
|
||||
ternaryFunc: bifs.BIF_rightpad,
|
||||
examples: []string{
|
||||
`rightpad("abcdefg", 10 , "*") gives "abcdefg***".`,
|
||||
`rightpad("abcdefg", 10 , "XY") gives "abcdefgXY".`,
|
||||
`rightpad("1234567", 10 , "0") gives "1234567000".`,
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: "format",
|
||||
class: FUNC_CLASS_STRING,
|
||||
|
|
|
|||
|
|
@ -192,17 +192,17 @@ MILLER(1) MILLER(1)
|
|||
invqnorm is_absent is_array is_bool is_boolean is_empty is_empty_map is_error
|
||||
is_float is_int is_map is_nan is_nonempty_map is_not_array is_not_empty
|
||||
is_not_map is_not_null is_null is_numeric is_present is_string joink joinkv
|
||||
joinv json_parse json_stringify latin1_to_utf8 leafcount length localtime2gmt
|
||||
localtime2sec log log10 log1p logifit lstrip madd mapdiff mapexcept mapselect
|
||||
mapsum max md5 mexp min mmul msub os pow qnorm reduce regextract
|
||||
regextract_or_else round roundm rstrip sec2dhms sec2gmt sec2gmtdate sec2hms
|
||||
sec2localdate sec2localtime select sgn sha1 sha256 sha512 sin sinh sort splita
|
||||
splitax splitkv splitkvx splitnv splitnvx sqrt ssub strftime strftime_local
|
||||
string strip strlen strptime strptime_local sub substr substr0 substr1 system
|
||||
systime systimeint tan tanh tolower toupper truncate typeof unflatten unformat
|
||||
unformatx uptime urand urand32 urandelement urandint urandrange utf8_to_latin1
|
||||
version ! != !=~ % & && * ** + - . .* .+ .- ./ / // < << <= <=> == =~ > >= >>
|
||||
>>> ?: ?? ??? ^ ^^ | || ~
|
||||
joinv json_parse json_stringify latin1_to_utf8 leafcount leftpad length
|
||||
localtime2gmt localtime2sec log log10 log1p logifit lstrip madd mapdiff
|
||||
mapexcept mapselect mapsum max md5 mexp min mmul msub os pow qnorm reduce
|
||||
regextract regextract_or_else rightpad round roundm rstrip sec2dhms sec2gmt
|
||||
sec2gmtdate sec2hms sec2localdate sec2localtime select sgn sha1 sha256 sha512
|
||||
sin sinh sort splita splitax splitkv splitkvx splitnv splitnvx sqrt ssub
|
||||
strftime strftime_local string strip strlen strptime strptime_local sub substr
|
||||
substr0 substr1 system systime systimeint tan tanh tolower toupper truncate
|
||||
typeof unflatten unformat unformatx uptime urand urand32 urandelement urandint
|
||||
urandrange utf8_to_latin1 version ! != !=~ % & && * ** + - . .* .+ .- ./ / //
|
||||
< << <= <=> == =~ > >= >> >>> ?: ?? ??? ^ ^^ | || ~
|
||||
|
||||
1mCOMMENTS-IN-DATA FLAGS0m
|
||||
Miller lets you put comments in your data, such as
|
||||
|
|
@ -2438,6 +2438,13 @@ MILLER(1) MILLER(1)
|
|||
1mleafcount0m
|
||||
(class=collections #args=1) Counts total number of terminal values in map/array. For single-level map/array, same as length.
|
||||
|
||||
1mleftpad0m
|
||||
(class=string #args=3) Left-pads first argument to at most the specified length (second, integer argument) using specified pad value (third, string argument). If the first argument is not a string, it will be stringified first.
|
||||
Examples:
|
||||
leftpad("abcdefg", 10 , "*") gives "***abcdefg".
|
||||
leftpad("abcdefg", 10 , "XY") gives "XYabcdefg".
|
||||
leftpad("1234567", 10 , "0") gives "0001234567".
|
||||
|
||||
1mlength0m
|
||||
(class=collections #args=1) Counts number of top-level entries in array/map. Scalars have length 1.
|
||||
|
||||
|
|
@ -2528,6 +2535,13 @@ MILLER(1) MILLER(1)
|
|||
regextract_or_else("index ab09 file", "[a-z][a-z][0-9][0-9]", "nonesuch") gives "ab09"
|
||||
regextract_or_else("index a999 file", "[a-z][a-z][0-9][0-9]", "nonesuch") gives "nonesuch"
|
||||
|
||||
1mrightpad0m
|
||||
(class=string #args=3) Right-pads first argument to at most the specified length (second, integer argument) using specified pad value (third, string argument). If the first argument is not a string, it will be stringified first.
|
||||
Examples:
|
||||
rightpad("abcdefg", 10 , "*") gives "abcdefg***".
|
||||
rightpad("abcdefg", 10 , "XY") gives "abcdefgXY".
|
||||
rightpad("1234567", 10 , "0") gives "1234567000".
|
||||
|
||||
1mround0m
|
||||
(class=math #args=1) Round to nearest integer.
|
||||
|
||||
|
|
@ -3276,4 +3290,4 @@ MILLER(1) MILLER(1)
|
|||
|
||||
|
||||
|
||||
2023-01-28 MILLER(1)
|
||||
2023-02-26 MILLER(1)
|
||||
|
|
|
|||
52
man/mlr.1
52
man/mlr.1
|
|
@ -2,12 +2,12 @@
|
|||
.\" Title: mlr
|
||||
.\" Author: [see the "AUTHOR" section]
|
||||
.\" Generator: ./mkman.rb
|
||||
.\" Date: 2023-01-28
|
||||
.\" Date: 2023-02-26
|
||||
.\" Manual: \ \&
|
||||
.\" Source: \ \&
|
||||
.\" Language: English
|
||||
.\"
|
||||
.TH "MILLER" "1" "2023-01-28" "\ \&" "\ \&"
|
||||
.TH "MILLER" "1" "2023-02-26" "\ \&" "\ \&"
|
||||
.\" -----------------------------------------------------------------
|
||||
.\" * Portability definitions
|
||||
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
@ -239,17 +239,17 @@ gmt2localtime gmt2sec gssub gsub haskey hexfmt hms2fsec hms2sec hostname int
|
|||
invqnorm is_absent is_array is_bool is_boolean is_empty is_empty_map is_error
|
||||
is_float is_int is_map is_nan is_nonempty_map is_not_array is_not_empty
|
||||
is_not_map is_not_null is_null is_numeric is_present is_string joink joinkv
|
||||
joinv json_parse json_stringify latin1_to_utf8 leafcount length localtime2gmt
|
||||
localtime2sec log log10 log1p logifit lstrip madd mapdiff mapexcept mapselect
|
||||
mapsum max md5 mexp min mmul msub os pow qnorm reduce regextract
|
||||
regextract_or_else round roundm rstrip sec2dhms sec2gmt sec2gmtdate sec2hms
|
||||
sec2localdate sec2localtime select sgn sha1 sha256 sha512 sin sinh sort splita
|
||||
splitax splitkv splitkvx splitnv splitnvx sqrt ssub strftime strftime_local
|
||||
string strip strlen strptime strptime_local sub substr substr0 substr1 system
|
||||
systime systimeint tan tanh tolower toupper truncate typeof unflatten unformat
|
||||
unformatx uptime urand urand32 urandelement urandint urandrange utf8_to_latin1
|
||||
version ! != !=~ % & && * ** + - . .* .+ .- ./ / // < << <= <=> == =~ > >= >>
|
||||
>>> ?: ?? ??? ^ ^^ | || ~
|
||||
joinv json_parse json_stringify latin1_to_utf8 leafcount leftpad length
|
||||
localtime2gmt localtime2sec log log10 log1p logifit lstrip madd mapdiff
|
||||
mapexcept mapselect mapsum max md5 mexp min mmul msub os pow qnorm reduce
|
||||
regextract regextract_or_else rightpad round roundm rstrip sec2dhms sec2gmt
|
||||
sec2gmtdate sec2hms sec2localdate sec2localtime select sgn sha1 sha256 sha512
|
||||
sin sinh sort splita splitax splitkv splitkvx splitnv splitnvx sqrt ssub
|
||||
strftime strftime_local string strip strlen strptime strptime_local sub substr
|
||||
substr0 substr1 system systime systimeint tan tanh tolower toupper truncate
|
||||
typeof unflatten unformat unformatx uptime urand urand32 urandelement urandint
|
||||
urandrange utf8_to_latin1 version ! != !=~ % & && * ** + - . .* .+ .- ./ / //
|
||||
< << <= <=> == =~ > >= >> >>> ?: ?? ??? ^ ^^ | || ~
|
||||
.fi
|
||||
.if n \{\
|
||||
.RE
|
||||
|
|
@ -3591,6 +3591,19 @@ $* = latin1_to_utf8($*)
|
|||
.fi
|
||||
.if n \{\
|
||||
.RE
|
||||
.SS "leftpad"
|
||||
.if n \{\
|
||||
.RS 0
|
||||
.\}
|
||||
.nf
|
||||
(class=string #args=3) Left-pads first argument to at most the specified length (second, integer argument) using specified pad value (third, string argument). If the first argument is not a string, it will be stringified first.
|
||||
Examples:
|
||||
leftpad("abcdefg", 10 , "*") gives "***abcdefg".
|
||||
leftpad("abcdefg", 10 , "XY") gives "XYabcdefg".
|
||||
leftpad("1234567", 10 , "0") gives "0001234567".
|
||||
.fi
|
||||
.if n \{\
|
||||
.RE
|
||||
.SS "length"
|
||||
.if n \{\
|
||||
.RS 0
|
||||
|
|
@ -3831,6 +3844,19 @@ regextract_or_else("index a999 file", "[a-z][a-z][0-9][0-9]", "nonesuch") gives
|
|||
.fi
|
||||
.if n \{\
|
||||
.RE
|
||||
.SS "rightpad"
|
||||
.if n \{\
|
||||
.RS 0
|
||||
.\}
|
||||
.nf
|
||||
(class=string #args=3) Right-pads first argument to at most the specified length (second, integer argument) using specified pad value (third, string argument). If the first argument is not a string, it will be stringified first.
|
||||
Examples:
|
||||
rightpad("abcdefg", 10 , "*") gives "abcdefg***".
|
||||
rightpad("abcdefg", 10 , "XY") gives "abcdefgXY".
|
||||
rightpad("1234567", 10 , "0") gives "1234567000".
|
||||
.fi
|
||||
.if n \{\
|
||||
.RE
|
||||
.SS "round"
|
||||
.if n \{\
|
||||
.RS 0
|
||||
|
|
|
|||
1
test/cases/dsl-leftpad-rightpad/L001/cmd
Normal file
1
test/cases/dsl-leftpad-rightpad/L001/cmd
Normal file
|
|
@ -0,0 +1 @@
|
|||
mlr --from test/input/abixy --d2p put -f ${CASEDIR}/mlr
|
||||
0
test/cases/dsl-leftpad-rightpad/L001/experr
Normal file
0
test/cases/dsl-leftpad-rightpad/L001/experr
Normal file
11
test/cases/dsl-leftpad-rightpad/L001/expout
Normal file
11
test/cases/dsl-leftpad-rightpad/L001/expout
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
a b i x y
|
||||
**pan pan 1 0.34679014 0.72680286
|
||||
**eks pan 2 0.75867996 0.52215111
|
||||
**wye wye 3 0.20460331 0.33831853
|
||||
**eks wye 4 0.38139939 0.13418874
|
||||
**wye pan 5 0.57328892 0.86362447
|
||||
**zee pan 6 0.52712616 0.49322129
|
||||
**eks zee 7 0.61178406 0.18788492
|
||||
**zee wye 8 0.59855401 0.97618139
|
||||
**hat wye 9 0.03144188 0.74955076
|
||||
**pan wye 10 0.50262601 0.95261836
|
||||
1
test/cases/dsl-leftpad-rightpad/L001/mlr
Normal file
1
test/cases/dsl-leftpad-rightpad/L001/mlr
Normal file
|
|
@ -0,0 +1 @@
|
|||
$a = leftpad($a, 5, "*")
|
||||
1
test/cases/dsl-leftpad-rightpad/L002/cmd
Normal file
1
test/cases/dsl-leftpad-rightpad/L002/cmd
Normal file
|
|
@ -0,0 +1 @@
|
|||
mlr --from test/input/abixy --d2p put -f ${CASEDIR}/mlr
|
||||
0
test/cases/dsl-leftpad-rightpad/L002/experr
Normal file
0
test/cases/dsl-leftpad-rightpad/L002/experr
Normal file
11
test/cases/dsl-leftpad-rightpad/L002/expout
Normal file
11
test/cases/dsl-leftpad-rightpad/L002/expout
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
a b i x y
|
||||
pan pan 00001 0.34679014 0.72680286
|
||||
eks pan 00002 0.75867996 0.52215111
|
||||
wye wye 00003 0.20460331 0.33831853
|
||||
eks wye 00004 0.38139939 0.13418874
|
||||
wye pan 00005 0.57328892 0.86362447
|
||||
zee pan 00006 0.52712616 0.49322129
|
||||
eks zee 00007 0.61178406 0.18788492
|
||||
zee wye 00008 0.59855401 0.97618139
|
||||
hat wye 00009 0.03144188 0.74955076
|
||||
pan wye 00010 0.50262601 0.95261836
|
||||
1
test/cases/dsl-leftpad-rightpad/L002/mlr
Normal file
1
test/cases/dsl-leftpad-rightpad/L002/mlr
Normal file
|
|
@ -0,0 +1 @@
|
|||
$i = leftpad($i, 5, "0")
|
||||
1
test/cases/dsl-leftpad-rightpad/L003/cmd
Normal file
1
test/cases/dsl-leftpad-rightpad/L003/cmd
Normal file
|
|
@ -0,0 +1 @@
|
|||
mlr --from test/input/abixy --d2p put -f ${CASEDIR}/mlr
|
||||
0
test/cases/dsl-leftpad-rightpad/L003/experr
Normal file
0
test/cases/dsl-leftpad-rightpad/L003/experr
Normal file
11
test/cases/dsl-leftpad-rightpad/L003/expout
Normal file
11
test/cases/dsl-leftpad-rightpad/L003/expout
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
a b i x y
|
||||
pan pan 00001 0.34679014 0.72680286
|
||||
eks pan 00002 0.75867996 0.52215111
|
||||
wye wye 00003 0.20460331 0.33831853
|
||||
eks wye 00004 0.38139939 0.13418874
|
||||
wye pan 00005 0.57328892 0.86362447
|
||||
zee pan 00006 0.52712616 0.49322129
|
||||
eks zee 00007 0.61178406 0.18788492
|
||||
zee wye 00008 0.59855401 0.97618139
|
||||
hat wye 00009 0.03144188 0.74955076
|
||||
pan wye 00010 0.50262601 0.95261836
|
||||
1
test/cases/dsl-leftpad-rightpad/L003/mlr
Normal file
1
test/cases/dsl-leftpad-rightpad/L003/mlr
Normal file
|
|
@ -0,0 +1 @@
|
|||
$i = leftpad($i, 5, 0)
|
||||
1
test/cases/dsl-leftpad-rightpad/L004/cmd
Normal file
1
test/cases/dsl-leftpad-rightpad/L004/cmd
Normal file
|
|
@ -0,0 +1 @@
|
|||
mlr --from test/input/abixy --d2p put -f ${CASEDIR}/mlr
|
||||
0
test/cases/dsl-leftpad-rightpad/L004/experr
Normal file
0
test/cases/dsl-leftpad-rightpad/L004/experr
Normal file
11
test/cases/dsl-leftpad-rightpad/L004/expout
Normal file
11
test/cases/dsl-leftpad-rightpad/L004/expout
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
a b i x y
|
||||
pan pan 1 0.34679014 0.72680286
|
||||
eks pan 2 0.75867996 0.52215111
|
||||
wye wye 3 0.20460331 0.33831853
|
||||
eks wye 4 0.38139939 0.13418874
|
||||
wye pan 5 0.57328892 0.86362447
|
||||
zee pan 6 0.52712616 0.49322129
|
||||
eks zee 7 0.61178406 0.18788492
|
||||
zee wye 8 0.59855401 0.97618139
|
||||
hat wye 9 0.03144188 0.74955076
|
||||
pan wye 10 0.50262601 0.95261836
|
||||
1
test/cases/dsl-leftpad-rightpad/L004/mlr
Normal file
1
test/cases/dsl-leftpad-rightpad/L004/mlr
Normal file
|
|
@ -0,0 +1 @@
|
|||
$a = leftpad($a, 2, "X")
|
||||
1
test/cases/dsl-leftpad-rightpad/L005/cmd
Normal file
1
test/cases/dsl-leftpad-rightpad/L005/cmd
Normal file
|
|
@ -0,0 +1 @@
|
|||
mlr --from test/input/abixy --d2p put -f ${CASEDIR}/mlr
|
||||
0
test/cases/dsl-leftpad-rightpad/L005/experr
Normal file
0
test/cases/dsl-leftpad-rightpad/L005/experr
Normal file
11
test/cases/dsl-leftpad-rightpad/L005/expout
Normal file
11
test/cases/dsl-leftpad-rightpad/L005/expout
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
a b i x y
|
||||
XYXYXYpan pan 1 0.34679014 0.72680286
|
||||
XYXYXYeks pan 2 0.75867996 0.52215111
|
||||
XYXYXYwye wye 3 0.20460331 0.33831853
|
||||
XYXYXYeks wye 4 0.38139939 0.13418874
|
||||
XYXYXYwye pan 5 0.57328892 0.86362447
|
||||
XYXYXYzee pan 6 0.52712616 0.49322129
|
||||
XYXYXYeks zee 7 0.61178406 0.18788492
|
||||
XYXYXYzee wye 8 0.59855401 0.97618139
|
||||
XYXYXYhat wye 9 0.03144188 0.74955076
|
||||
XYXYXYpan wye 10 0.50262601 0.95261836
|
||||
1
test/cases/dsl-leftpad-rightpad/L005/mlr
Normal file
1
test/cases/dsl-leftpad-rightpad/L005/mlr
Normal file
|
|
@ -0,0 +1 @@
|
|||
$a = leftpad($a, 10, "XY")
|
||||
1
test/cases/dsl-leftpad-rightpad/R001/cmd
Normal file
1
test/cases/dsl-leftpad-rightpad/R001/cmd
Normal file
|
|
@ -0,0 +1 @@
|
|||
mlr --from test/input/abixy --d2p put -f ${CASEDIR}/mlr
|
||||
0
test/cases/dsl-leftpad-rightpad/R001/experr
Normal file
0
test/cases/dsl-leftpad-rightpad/R001/experr
Normal file
11
test/cases/dsl-leftpad-rightpad/R001/expout
Normal file
11
test/cases/dsl-leftpad-rightpad/R001/expout
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
a b i x y
|
||||
pan** pan 1 0.34679014 0.72680286
|
||||
eks** pan 2 0.75867996 0.52215111
|
||||
wye** wye 3 0.20460331 0.33831853
|
||||
eks** wye 4 0.38139939 0.13418874
|
||||
wye** pan 5 0.57328892 0.86362447
|
||||
zee** pan 6 0.52712616 0.49322129
|
||||
eks** zee 7 0.61178406 0.18788492
|
||||
zee** wye 8 0.59855401 0.97618139
|
||||
hat** wye 9 0.03144188 0.74955076
|
||||
pan** wye 10 0.50262601 0.95261836
|
||||
1
test/cases/dsl-leftpad-rightpad/R001/mlr
Normal file
1
test/cases/dsl-leftpad-rightpad/R001/mlr
Normal file
|
|
@ -0,0 +1 @@
|
|||
$a = rightpad($a, 5, "*")
|
||||
1
test/cases/dsl-leftpad-rightpad/R002/cmd
Normal file
1
test/cases/dsl-leftpad-rightpad/R002/cmd
Normal file
|
|
@ -0,0 +1 @@
|
|||
mlr --from test/input/abixy --d2p put -f ${CASEDIR}/mlr
|
||||
0
test/cases/dsl-leftpad-rightpad/R002/experr
Normal file
0
test/cases/dsl-leftpad-rightpad/R002/experr
Normal file
11
test/cases/dsl-leftpad-rightpad/R002/expout
Normal file
11
test/cases/dsl-leftpad-rightpad/R002/expout
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
a b i x y
|
||||
pan pan 10000 0.34679014 0.72680286
|
||||
eks pan 20000 0.75867996 0.52215111
|
||||
wye wye 30000 0.20460331 0.33831853
|
||||
eks wye 40000 0.38139939 0.13418874
|
||||
wye pan 50000 0.57328892 0.86362447
|
||||
zee pan 60000 0.52712616 0.49322129
|
||||
eks zee 70000 0.61178406 0.18788492
|
||||
zee wye 80000 0.59855401 0.97618139
|
||||
hat wye 90000 0.03144188 0.74955076
|
||||
pan wye 10000 0.50262601 0.95261836
|
||||
1
test/cases/dsl-leftpad-rightpad/R002/mlr
Normal file
1
test/cases/dsl-leftpad-rightpad/R002/mlr
Normal file
|
|
@ -0,0 +1 @@
|
|||
$i = rightpad($i, 5, "0")
|
||||
1
test/cases/dsl-leftpad-rightpad/R003/cmd
Normal file
1
test/cases/dsl-leftpad-rightpad/R003/cmd
Normal file
|
|
@ -0,0 +1 @@
|
|||
mlr --from test/input/abixy --d2p put -f ${CASEDIR}/mlr
|
||||
0
test/cases/dsl-leftpad-rightpad/R003/experr
Normal file
0
test/cases/dsl-leftpad-rightpad/R003/experr
Normal file
11
test/cases/dsl-leftpad-rightpad/R003/expout
Normal file
11
test/cases/dsl-leftpad-rightpad/R003/expout
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
a b i x y
|
||||
pan pan 10000 0.34679014 0.72680286
|
||||
eks pan 20000 0.75867996 0.52215111
|
||||
wye wye 30000 0.20460331 0.33831853
|
||||
eks wye 40000 0.38139939 0.13418874
|
||||
wye pan 50000 0.57328892 0.86362447
|
||||
zee pan 60000 0.52712616 0.49322129
|
||||
eks zee 70000 0.61178406 0.18788492
|
||||
zee wye 80000 0.59855401 0.97618139
|
||||
hat wye 90000 0.03144188 0.74955076
|
||||
pan wye 10000 0.50262601 0.95261836
|
||||
1
test/cases/dsl-leftpad-rightpad/R003/mlr
Normal file
1
test/cases/dsl-leftpad-rightpad/R003/mlr
Normal file
|
|
@ -0,0 +1 @@
|
|||
$i = rightpad($i, 5, 0)
|
||||
1
test/cases/dsl-leftpad-rightpad/R004/cmd
Normal file
1
test/cases/dsl-leftpad-rightpad/R004/cmd
Normal file
|
|
@ -0,0 +1 @@
|
|||
mlr --from test/input/abixy --d2p put -f ${CASEDIR}/mlr
|
||||
0
test/cases/dsl-leftpad-rightpad/R004/experr
Normal file
0
test/cases/dsl-leftpad-rightpad/R004/experr
Normal file
11
test/cases/dsl-leftpad-rightpad/R004/expout
Normal file
11
test/cases/dsl-leftpad-rightpad/R004/expout
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
a b i x y
|
||||
pan pan 1 0.34679014 0.72680286
|
||||
eks pan 2 0.75867996 0.52215111
|
||||
wye wye 3 0.20460331 0.33831853
|
||||
eks wye 4 0.38139939 0.13418874
|
||||
wye pan 5 0.57328892 0.86362447
|
||||
zee pan 6 0.52712616 0.49322129
|
||||
eks zee 7 0.61178406 0.18788492
|
||||
zee wye 8 0.59855401 0.97618139
|
||||
hat wye 9 0.03144188 0.74955076
|
||||
pan wye 10 0.50262601 0.95261836
|
||||
1
test/cases/dsl-leftpad-rightpad/R004/mlr
Normal file
1
test/cases/dsl-leftpad-rightpad/R004/mlr
Normal file
|
|
@ -0,0 +1 @@
|
|||
$a = rightpad($a, 2, "X")
|
||||
1
test/cases/dsl-leftpad-rightpad/R005/cmd
Normal file
1
test/cases/dsl-leftpad-rightpad/R005/cmd
Normal file
|
|
@ -0,0 +1 @@
|
|||
mlr --from test/input/abixy --d2p put -f ${CASEDIR}/mlr
|
||||
0
test/cases/dsl-leftpad-rightpad/R005/experr
Normal file
0
test/cases/dsl-leftpad-rightpad/R005/experr
Normal file
11
test/cases/dsl-leftpad-rightpad/R005/expout
Normal file
11
test/cases/dsl-leftpad-rightpad/R005/expout
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
a b i x y
|
||||
panXYXYXY pan 1 0.34679014 0.72680286
|
||||
eksXYXYXY pan 2 0.75867996 0.52215111
|
||||
wyeXYXYXY wye 3 0.20460331 0.33831853
|
||||
eksXYXYXY wye 4 0.38139939 0.13418874
|
||||
wyeXYXYXY pan 5 0.57328892 0.86362447
|
||||
zeeXYXYXY pan 6 0.52712616 0.49322129
|
||||
eksXYXYXY zee 7 0.61178406 0.18788492
|
||||
zeeXYXYXY wye 8 0.59855401 0.97618139
|
||||
hatXYXYXY wye 9 0.03144188 0.74955076
|
||||
panXYXYXY wye 10 0.50262601 0.95261836
|
||||
1
test/cases/dsl-leftpad-rightpad/R005/mlr
Normal file
1
test/cases/dsl-leftpad-rightpad/R005/mlr
Normal file
|
|
@ -0,0 +1 @@
|
|||
$a = rightpad($a, 10, "XY")
|
||||
Loading…
Add table
Add a link
Reference in a new issue