Get the bottom line of a file to the top of the file

Hi,

i have a small requirement where i have to get the bottom most line from a file to the topmost position. a small example is shown below..

$ cat beep.txt
It is first documented as being played in southern England.
In the 16th century.
By the end of the 18th century,
Cricket is a bat-and-ball team sport.

i want it as

$ cat beep.txt
Cricket is a bat-and-ball team sport.
It is first documented as being played in southern England.
In the 16th century.
By the end of the 18th century,

the problem is this file gets updated daily so each time i run the script i want to get the bottom most thing in the top most position....

Thanks for the help in advance :slight_smile:

You can use this code:

(
tail -1 beep.txt
sed "$ d" beep.txt
) > beep.new.txt

You can use sed for this as

Code:


cat beep.txt | sed -ne '1!G' -e 'h' -e '$p'

I think that it isn�t valid for his requirement. That command will reverse all lines of the file. Isn�t it ?

@pogdorica

yes you are right . The code you gave is working like miracle and is as per the requirement. Thanks for the effort.:slight_smile:

ever heard of "tac" (reverse cat)