I agree with the moral of the story. However, you were not completely off on your idea to condense to 1 statement. Using your test, the following works:
sort -n -t, -k1,1 -k2,2 -u test.dat
Sort needs to look at the 2 fields independently. I used to do a lot of shell scripting, and sort was a frequent tool. The other thing to watch for is some systems (difference between Sequent DYNIX and HP/UX that I know of) requires '-t ,' and others '-t,'. If you don't get it right on your system, sort acts very strange.
None of this is documented well, that I've seen.
As someone else put it, "Unit Test, Unit Test, Unit Test".
I very frequently, will do the test you did BEFORE implementing a change, just to verify my understanding of how things work....
While we are giving advice:
Never believe a customer/user when they say "always" or "never"....
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.