Skip to content
Advertisement

How to get Linux to only show the last paragraph in a text file using cat?

I have a school assignment, which says the following:

Use the cat command, suitably modified, to show only the last paragraph in the textfile

I have already checked on https://unix.stackexchange.com/questions/308032/modifying-cat-command-to-number-paragraphs-and-display-last-paragraph-only, but it wasn’t very helpful.

I am aware that you can do this without cat, but my school says I have to use the cat command.

Thanks! 😉

Edit: I used cat -n thefile | tail -n1 and it worked perfectly. Thank you Peter Bowyer!

Advertisement

Answer

Assuming that you had one paragraph per line…..
cat -n thefile | tail -n1

Advertisement