He had a requirement - to take a list of items ( a text file ) and invert the list.
Initially I thought he meant that he wanted to sort the list, which seemed simple.
Here's a list: -
cat list.txt
Cat
Rabbit
Dog
Gerbil
Hamster
Horse
Rhino
Hippo
Alosaur
Rabbit
Dog
Gerbil
Hamster
Horse
Rhino
Hippo
Alosaur
so here's the sorted list: -
sort list.txt
Alosaur
Cat
Dog
Gerbil
Hamster
Hippo
Horse
Rabbit
Rhino
Cat
Dog
Gerbil
Hamster
Hippo
Horse
Rabbit
Rhino
and here's the reverse sort: -
sort -r list.txt
Rhino
Rabbit
Horse
Hippo
Hamster
Gerbil
Dog
Cat
Alosaur
Rabbit
Horse
Hippo
Hamster
Gerbil
Dog
Cat
Alosaur
but NO, I didn't understand his requirement - he wanted the list reversed BUT not sorted.
Introducing …. TAC
Why tac ? 'cos it's the reverse of cat :-)
Unix and puns, what's not to like
So here's the list, reversed BUT NOT sorted: -
tac list.txt
Alosaur
Hippo
Rhino
Horse
Hamster
Gerbil
Dog
Rabbit
Cat
Hippo
Rhino
Horse
Hamster
Gerbil
Dog
Rabbit
Cat
2 comments:
That basically sounds like a LIFO (Last in First Out) requirement.
Hi Ben
Yep, bang on the money :-)
Cheers, Dave
Post a Comment