Path: utzoo!attcan!uunet!lll-winken!ames!elan!jlo From: jlo@elan.UUCP (Jeff Lo) Newsgroups: comp.unix.questions Subject: Re: sorting and reversing lines of a file Keywords: sort reverse Message-ID: <422@elan.UUCP> Date: 26 Jan 89 22:52:37 GMT References: <9056@burdvax.PRC.Unisys.COM> Reply-To: jlo@elan.UUCP (Jeff Lo) Organization: Elan Computer Group, Inc., Palo Alto, CA Lines: 48 In article <9056@burdvax.PRC.Unisys.COM> lang@pearl.PRC.Unisys.COM (Francois-Michel Lang) writes: >I need utilities to do two things: >(1) reverse the order of lines in a file > but leave the lines themselves intact. > The Unix utility does just the opposite of this. > > E.g., if the file "f" contains > line1 > line2 > line3 > I want to produce > line 3 > line 2 > line 1 ^ spaces? > I have an awk program to do this, > but I'm sure some clever soul out there can do much better. I assume you meant for line1 line2 line3 to become line3 line2 line1 Assuming this is the case, you can use a shell script like this: #!/bin/sh for file in $* ; do ed - $file << __EOF__ g/^/.m0 w q __EOF__ done This will use "ed" to reverse the order of the lines in each file passed as an argument to the script. This and many other neat "ed" tricks are in the quiz program. Try: quiz function ed-command -- Jeff Lo ..!{ames,hplabs,uunet}!elan!jlo Elan Computer Group, Inc. (415) 322-2450