On Fri, 20 May 2011, Kurt H Maier wrote:
> Any reason not to sort(1) them before you feed them to perl? And
> don't get me wrong: perl is my favorite language, but wouldn't
> something akin to
>
> history | sort -r | sed '1d; s/^[ \t]*[0-9]*[ \t]*//'
>
> work just as well?
I would've changed it to use `sed` myself (since it was just doing a
single substitution), but I don't know it well enough to know if there's
an equivalent for the end of my `perl` version: 'print unless eof'. (I
love `sed 1q`, which I learned here recently from Ethan Grammatikidis.)
The reason for dropping the last line is that by the time it's executed
here `history` contains the currently-executing command. By simply
reversing (and not sorting), things end up in reverse chronological
order. Without lopping off the last line, the choices would always
unhelpfully include the 'h' being executed.
-- Best, BenReceived on Fri May 20 2011 - 20:19:43 CEST
This archive was generated by hypermail 2.2.0 : Fri May 20 2011 - 20:24:03 CEST