Search code examples
shelldarwin

Strange behavior of uniq on darwin shells


I've used 'uniq -d -c file' in many shell scripts on linux machines, and it works. On my MAC (OS X 10.6.7 with developer tools installed) it doesn't seems to work:

$ uniq -d -c testfile.txt 
usage: uniq [-c | -d | -u] [-i] [-f fields] [-s chars] [input [output]]

It would be nice if anyone could checks this.


Solution

  • Well, it's right there in the Usage message. [ -c | -d | -u] means you can use one of those possibilities, not two.

    Since OSX is based on BSD, you can check that here or, thanks to Ignacio, the more Apple-specific one here.

    If you want to achieve a similar output, you could use:

    do_your_thing | uniq -c | grep -v '^ *1 '
    

    which will strip out all those coalesced lines that have a count of one.