There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies.
Reply to Peter Passchier:
February 22nd, 2009 at 11:23 am
Peter came up with:
awk ‘BEGIN {srand();a=rand()} a!=$0 {a=$0;print}’
No need to use a random value (insecure too - Sun awk only uses 32768 distinct random values). Best initialiser for a variable is "\n", because that can never be in your input but you can stuff it in a string.
Alternative tool to deal with initial conditions is to factor in a test for first line: NR == 1
(I didn’t understand what the semicolon after a!=$0 does or means, so I removed it, and added a print action whenever the line isn’t equal to the previous.)
The ; is a trick. It makes the one-liner into two lines (!). Before the ";" is a match without an action, so it prints if true. After the ";" is an action without a match, so it always stores the value.
I am being sponsored by Syntress! They bought me an amazing dedicated server to run catonmat on. If you're looking web services, I highly recommend the Syntress guys!
Education Sponsors
I am being sponsored by A-Writer! If you ever need help with essay writing, look no further than A-Writer! They will help you with your writing in as quickly as 3 hours!
Reply to Peter Passchier:
February 22nd, 2009 at 11:23 am
Peter came up with:
awk ‘BEGIN {srand();a=rand()} a!=$0 {a=$0;print}’
No need to use a random value (insecure too - Sun awk only uses 32768 distinct random values). Best initialiser for a variable is "\n", because that can never be in your input but you can stuff it in a string.
Alternative tool to deal with initial conditions is to factor in a test for first line: NR == 1
(I didn’t understand what the semicolon after a!=$0 does or means, so I removed it, and added a print action whenever the line isn’t equal to the previous.)
The ; is a trick. It makes the one-liner into two lines (!). Before the ";" is a match without an action, so it prints if true. After the ";" is an action without a match, so it always stores the value.
Reply To This Comment