Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!usc!ucsd!ogccse!littlei!omepd!merlyn From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.unix.questions Subject: Re: Reversing a file? Message-ID: <5013@omepd.UUCP> Date: 5 Oct 89 14:59:42 GMT References: <2283@munnari.oz.au> Sender: news@omepd.UUCP Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Hillsboro, Oregon, USA Lines: 21 In-reply-to: ok@cs.mu.oz.au (Richard O'Keefe) In article <2283@munnari.oz.au>, ok@cs (Richard O'Keefe) writes: | 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 $* | sort -nr | sed -e 's/^.......//' | In System V: | pr -t -n6 $* | sort -nr | cut -f2- In Perl, of course, it's perl -e 'unshift(a,$_) while (); print @a;' which works even when 'tail -r' (another solution in another post) doesn't, provided you have the real/virtual memory to spare. Just another Perl hacker, -- /== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\ | on contract to Intel's iWarp project, Hillsboro, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn | \== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/