Reputation: 6921
The documentation for cut
(cf info cut
) says:
--output-delimiter=OUTPUT_DELIM_STRING
With `-f`, output fields are separated by OUTPUT_DELIM_STRING. The default with `-f` is to use the input delimiter. When using `-b` or `-c` to select ranges of byte or character offsets (as opposed to ranges of fields), output OUTPUT_DELIM_STRING between non-overlapping ranges of selected bytes.
My understanding is that therefore this:
echo abcdefghi | cut --output-delimiter=',' -c 1-2,5-6
Should give ab,ef
. But it prints abef
...
How do I achieve ab,ef
? Have I misunderstood the documentation?
Before closing as dupe, please note that:
awk
or sed
or perl
or bash
or (..) (see this similar question with an ugly accepted answer) but I am after a cut
solution, especially since the documentation says it should work.-c
and not -f
Upvotes: 1
Views: 2459
Reputation: 39434
In version 8.22, the behavior is as expected:
$ echo abcdefghi | cut --output-delimiter=',' -c 1-2,5-6
ab,ef
$ cut --version
cut (GNU coreutils) 8.22
Copyright (C) 2013 Free Software Foundation, Inc.
Given that you're using the 5.9 series, officially released around 2006, I think we can conclude this is a bug in that series. Given that you're on RedHat, your version likely has had security fixes back-ported, but not paper cut bugs like this one.
Solution would be to upgrade, or use an alternative tool as you've pointed out.
Upvotes: 1