Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!ginosko!uunet!munnari.oz.au!cs.mu.oz.au!ok
From: ok@cs.mu.oz.au (Richard O'Keefe)
Newsgroups: comp.unix.questions
Subject: Re: Reversing a file?
Message-ID: <2283@munnari.oz.au>
Date: 3 Oct 89 11:43:11 GMT
References: 
Sender: news@cs.mu.oz.au
Lines: 21

In article , montnaro@sprite.crd.ge.com (Skip Montanaro) writes:
>Does somebody have an elegant shell script for reversing the lines of a file?

In BSD systems,
	cat -n File
puts six-digit line numbers and a tab in front of every line.
In System V,
	pr -t -n6 File
will do this.
Now sort the lines in descending order of line number
    |	sort -nr
Now you want to throw away the line numbers.  In System V,
    |	cut -f2-
will do the job.  If you haven't got cut(1),
    |	sed -e 's/^.......//'
will strip off the spaces, digits, and tab.  So

In BSD systems:
	cat -n $* | sort -nr | sed -e 's/^.......//'
In System V:
	pr -t -n6 $* | sort -nr | cut -f2-