Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!ginosko!uunet!virtech!cpcahil From: cpcahil@virtech.UUCP (Conor P. Cahill) Newsgroups: comp.unix.questions Subject: Re: Reversing a file? Summary: how about grep | sort | sed Message-ID: <1224@virtech.UUCP> Date: 3 Oct 89 17:55:23 GMT References:Organization: Virtual Technologies Inc 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? I've come up with the following short one: How about the following pipeline: grep -n "\$" t.c | sort -rn | sed "s/^[0-9]*://" what this does is as follows: grep - get all lines of the file and number them sort - key is numeric and sort in reverse order sed - remove line numbers added by grep Good luck. -- +-----------------------------------------------------------------------+ | Conor P. Cahill uunet!virtech!cpcahil 703-430-9247 ! | Virtual Technologies Inc., P. O. Box 876, Sterling, VA 22170 | +-----------------------------------------------------------------------+