Reversing a file?

Mark Bush bush%ecs.oxford.ac.uk at nsfnet-relay.ac.uk
Sat Oct 7 03:41:48 AEST 1989


> Does somebody have an elegant shell script for reversing the lines of a
> file? I've come up with the following short one:

For all perl fans:

while (<>)
{
    $line{$.} = $_;
}

for ($i = $.; $i > 0; $i--)
{
    print $line{$i};
}

Mark Bush                      bush%uk.ac.oxford.prg at ac.uk
Teaching Support Programmer    bush%prg.oxford.ac.uk at nsfnet-relay.ac.uk
OUCL                           ...!uunet!mcvax!ukc!ox-prg!bush



More information about the Comp.unix.questions mailing list