Subject: bug#10365: [PATCH] uniq: add ability to skip last N chars or fields

From: Jim Meyering <[email-masked]>
Date: Mon, 26 Dec 2011 17:42:25 +0100

Pádraig Brady wrote:

> On 12/25/2011 12:54 PM, Adrien Kunysz wrote:
>> * doc/coreutils.texi: document the new feature
>> * src/uniq.c (find_end): new function
>> (check_file): use find_end() to determine when to stop comparing
>> (usage): document the new feature
>> (main): expose the new feature to user
>> * tests/misc/uniq: add tests to exercise the new code
>> ---
>>  doc/coreutils.texi |   17 +++++++++++++
>>  src/uniq.c         |   69 +++++++++++++++++++++++++++++++++++++++++++++++++---
>>  tests/misc/uniq    |   15 +++++++++++
>>  3 files changed, 97 insertions(+), 4 deletions(-)
>>
>> I have recently found myself wishing I could have uniq(1) skip
>> the last N fields before comparison. I am aware of the rev(1) trick
>> but I don't find it very satisfactory. So I ended up patching uniq
>> and implementing the feature for characters skipping as well.
>>
>> Documentation and tests included. Tests have also been run within
>> Valgrind on x86_64.
>
> Thank you for being so thorough.
>
> Hmm, this is quite unusual functionality.
> I was about to merge this with a previous feature request:
> http://debbugs.gnu.org/5832
> But in fact supporting --key would not provide this functionality.
>
> Why does `rev | uniq -f | rev` not suffice for you?
>
> BTW you would need to start the copyright assignment process for
> this feature, but we'd have to decide if it generally useful enough
> to proceed. Perhaps a concrete example would help.

I agree that it's borderline.
If we add this functionality, I'd prefer to do it without adding new
options.  Instead, just accept negative values for N in the three
options that accept counts:

    $ uniq --help|grep -w N
      -f, --skip-fields=N   avoid comparing the first N fields
      -s, --skip-chars=N    avoid comparing the first N characters
      -w, --check-chars=N   compare no more than N characters in lines