News for hackers. Stuff that matters.
Re:Shell Magic: Set Operations with uniq by kbob on Tuesday May 29, 2018 @08:22PM (#17183873)
Aaargh! "cat | sort" is an antipattern.

Sort accepts a list of files as arguments. "sort [flags] file1 file2 ..." is more concise, more efficient, and is less likely to run out of space.

Re:Shell Magic: Set Operations with uniq by mds on Tuesday May 29, 2018 @08:30PM (#17183912)
Someone always says this, but starting with cat sure makes it easier compose the command line. When working with big files, start with "head -1000 | sort | uniq ..." and switch to cat after you work out the command. Or you start composing the command and realize you need to sort on field 2, so insert a "cut" before the "sort" etc.
Re:Shell Magic: Set Operations with uniq by BenjiWiebe on Tuesday May 29, 2018 @08:29PM (#17183904)
And for people like me who want the file name first on the line, this format works in Bash at least:

</dir/file sort | uniq >outfile

Re:Shell Magic: Set Operations with uniq by fiddlerwoaroof on Wednesday May 30, 2018 @12:30AM (#17185080)
I always find it really confusing when the command-line begins with a redirect.
Re:Shell Magic: Set Operations with uniq by unixhero on Wednesday May 30, 2018 @04:05AM (#17185940)
Yes, how do you parse that - ie. what does it even mean?
Re:Shell Magic: Set Operations with uniq by moviuro on Wednesday May 30, 2018 @04:40AM (#17186086)

  > a # from stdout to file
  < a # simply the opposite operation: from file to stdin
Re:Shell Magic: Set Operations with uniq by fiddlerwoaroof on Wednesday May 30, 2018 @04:29AM (#17186038)
It's just a convention that redirects come after the command they're redirecting. There might be shell options that influence this, but I think all these are generally equivalent:

    foo bar < a
    foo < a bar
    < a foo bar
Re:Shell Magic: Set Operations with uniq by paxunix on Wednesday May 30, 2018 @12:09PM (#17188902)
It is POSIX shell parsing behaviour that redirections can appear anywhere in the command (obviously, not in the same word as another parameter, nor inside a quoted string). They have to be stripped out by the shell before execution: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3...