On 2023-08-01 18:27, Rob Landley wrote:
On 8/1/23 04:07, Dragan Simic wrote:
Add new command-line option and the required logic that allow multiple
consecutive delimiters to be treated as a single delimiter. Of
course,
this option is valid only with the cut's field mode.
This new feature should make cut much more usable in various
real-world
applications, some of which are already mentioned in the gotchas. For
example, merging the consecutive delimiters is very useful when cut is
used to process the outputs of various commands.
A year and a half ago I submitted cut -D -F -O to this list, which
included a
regex mode for delimiters that would allow you to do that in a generic
way:
-F like -f but the -d delimiter is interpreted as an extended regex
string
-D disables field sort/collate so -f 3,2,1-3 prints fields 3 2 1 2 3
-O specifies the output separator (default ' ' for -F, input delim
for -f).
The -d default value also changes, the toybox code for which is:
if (!TT.d) TT.d = FLAG(F) ? "[[:space:]][[:space:]]*" : "\t";
I.E. run of whitespace for -F, same old \t for -f. (There should be no
change to
any existing behavior unless you specify one or more of the new
options.)
These options have been in toybox since 2017 (commit 3eb69d412e79, I
think it
missed the Android 8.1 cutoff and wound up in 9? Um, "Oreo" and "Pie"
respectively.) They were merged into busybox in 2021 (commit
0068ce2fa0e3).
The coreutils developers showed interest in merging support, came up
with a
patch, and discussed it (defining --longopts for everything because
gnu, which I
added to toybox in commit 9b108ab90b63), but the discussion petered out
here:
https://lists.gnu.org/archive/html/coreutils/2022-01/msg00050.html
When I asked again after the next release, they said it would be in
9.2:
https://lists.gnu.org/archive/html/coreutils/2022-04/msg00010.html
In February of this year I asked again, and it was on the review list
for the
upcoming release:
https://lists.gnu.org/archive/html/coreutils/2023-02/msg00012.html
The coreutils 9.3 page on the web doesn't include the -DFO options:
https://www.gnu.org/software/coreutils/manual/coreutils.html#cut-invocation
Which means I still need to use "awk '{print $3}'" instead of "cut -DF
3" in
scripts I want to run on the host.
Thanks for a detailed summary! I'd have to perform a detailed review of
the code changes to say "yay" or "nay" to the merging of your patches,
but the described "-F" and "-D" options look good and I think they would
be very useful!
By the way, isn't the described "-O" option already covered by the
"--output-delimiter" option? However, having "-O" as the short alias
would be very useful. Can we have at least that merged?