Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!crdgw1!montnaro From: montnaro@sprite.crd.ge.com (Skip Montanaro) Newsgroups: comp.unix.questions Subject: Reversing a file? Message-ID:Date: 3 Oct 89 02:42:15 GMT Sender: news@crdgw1.crd.ge.com Reply-To: (Skip Montanaro) Organization: GE Corporate Research & Development, Schenectady, NY Lines: 22 Does somebody have an elegant shell script for reversing the lines of a file? I've come up with the following short one: ----------cut----------cut----------cut----------cut---------- #!/bin/sh read line if [ $? = 0 ] ; then $0 echo $line fi ----------cut----------cut----------cut----------cut---------- It has two obvious disadvantages. First, it won't work for very long files, since it uses Unix processes to simulate a stack of lines. Second, the Bourne shell's builtin read command doesn't preserve interword white space, separating words by the value of the IFS environment variable instead. It worked adequately for the task I originally intended, however - reversing the lines in my appointements file. -- Skip Montanaro (montanaro@crdgw1.ge.com)