[net.unix] reversing lines in a file

jhc@aber-cs.UUCP (James H. Cox) (09/16/85)

In article <2140@ukma.UUCP> slg@ukma.UUCP (Sean Gilley) writes:
>Uh.. folks, in our flavor UN*X, (4.2) ``tail'' has a -r option
>that does just that.  Don't people _like_ tail? :-)
>
>						Sean.
I think tail is a wonderful command, but its not much use for reversing
lines in a file because it gives up after a few lines -- you only get
the first screenful then tail stops.
>
>
>p.s.  I think it's time this discusion ended . . . or at least got moved
>      to net.unix.  These really aren't sources, and I appologise to
>      everyone out there for posting here . . . but this is where the
>      discussion is.
>
Consider it moved; surely a discussion ends when people run out of things
to say. {:-)

"Rambo aint tough, he just smells strong"



-- 
UUCP : { ENGLAND or WALES }!ukc!dcl-cs!aber-cs!jhc
JANET: jhc@uk.ac.aber.cs           PHONE:    +44 970 3111 x 3373	
Post: University College of Wales, Penglais, Aberystwyth, UK, SY23 3BZ.

POSER@SU-CSLI.ARPA (Bill Poser) (09/26/85)

The problem with tail -r giving you only a portion of the file is easily
overcome unless you are working with *very* large files or have very little
core (or don't have sources). The reason it does this is that tail reads
its input in chunks and you're only getting one. The chunk size is set
by a define. I forget the name of the parameter but it's pretty obvious.
I think it's set to 8192 in the distribution. Just change this to a suitable
larger value and recompile.
-------

nz@wucs.UUCP (Neal Ziring) (09/26/85)

	One way to reverse lines in a file is to use revgrep(1).

	Revgrep was posted to net.sources by yours truly about 3
weeks ago.  It does a grep, backwards, so 

	% revgrep '^' file.dat

reverses the lines of  file.dat.  Revgrep has no length limits.
If anyone missed revgrep on net.sources and would like a copy, 
I will be glad to mail it (or even re-post).

Anw%maths.nottingham.ac.uk@UCL-CS.ARPA (10/05/85)

		anw@UK.AC.Nott.Maths
	-- Andy Walker, Maths Dept, Nottingham Univ

		grep -n "" file.dat | sort -rn | sed "s/[0-9]*://"

	Possibly more in the spirit of Unix is

> reverses the lines of  file.dat. [...]
>
>	% revgrep '^' file.dat
>
>	[...] It does a grep, backwards, so
>	One way to reverse lines in a file is to use revgrep(1).