|
From: | Henrikki Almusa |
Subject: | Re: [coreutils] cut feature request |
Date: | Fri, 10 Sep 2010 12:25:35 +0300 |
User-agent: | Thunderbird 2.0.0.24 (X11/20100411) |
Laurent Lyaudet wrote:it would be useful that cut handles negative numbers parameters for columns and fields as "from the end" parameters. ... I think using awk or something similar is overkill for solving that problem.Why? I think awk is the perfect tool for it. It already handles the problem well. It is standard. Awk: $ echo one two three | awk '{print$NF}' three $ echo one two three | awk '{print$(NF-1)}' two Perl: $ echo one two three | perl -lane 'print $F[-1]' three If cut included all of the features of awk (or perl) then cut would also be overkill for the problem too, right? Except then there wouldn't be a way to avoid the bloat by using the small and light weight cut, because cut wouldn't be small and light weight anymore, right?
I'd like to add my voice to adding this feature as well. I have a table from which I want to retrieve 3rd and 2nd last columns. I can do this with perl
cat foo.csv | perl -lane 'print join("\t",@F[$#F-2 .. $#F-1])' > bar.csv I think it would be much nicer to be able to use cut in here. cat foo.csv | cut -f-2,-3 > bar.csvNobody is saying that all the functions of perl (or awk) should be in cut, but ability to start from end of line instead of start would be useful. Alternative to -N (as that can be mixed to other options or valid syntax) might be
cat foo.csv | cut --start-end -f2,3 > bar.csv Thanks, Ps. please CC me as I'm not on coreutils list. -- Henrikki Almusa
[Prev in Thread] | Current Thread | [Next in Thread] |