Wednesday, 16 August 2017

What's the opposite of "cat" ? Another in the "I did not know that" series

Thanks to a friend, Paul Smith, for sharing this.

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


so here's the sorted list: -

sort list.txt 

Alosaur
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


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

2 comments:

Ben Langhinrichs said...

That basically sounds like a LIFO (Last in First Out) requirement.

Dave Hay said...

Hi Ben

Yep, bang on the money :-)

Cheers, Dave

Reminder - installing podman and skopeo on Ubuntu 22.04

This follows on from: - Lest I forget - how to install pip on Ubuntu I had reason to install podman  and skopeo  on an Ubuntu box: - lsb_rel...