[net.sources] shortshort way of reversing the lines in a file

bandy@lll-crg.UUCP (Andrew Scott Beals) (09/01/85)

Recently, some Gentleman from the UK posted a program that reversed
the lines in a file. I figured that I should post this somewhat 
shorter solution.

----cute here, huh?----
/*
 * mirror the recursive way
 *
 */

#include <stdio.h>

main() {
    char	foo[BUFSIZ];

    if(gets(foo) == NULL) return;
    main();
    puts(foo);
}
----better cut here too----
At least I thought it was cute.

Disclaimer: this program has very little to do with what they
do here at Livermore.

stephen@dcl-cs.UUCP (Stephen J. Muir) (09/02/85)

In article <822@lll-crg.UUCP> bandy@lll-crg.UUCP (Andrew Scott Beals) writes:
>Recently, some Gentleman from the UK posted a program that reversed
>the lines in a file. I figured that I should post this somewhat 
>shorter solution.

At least give me the credit -- see the first line of the body of the article.

>#include <stdio.h>
>
>main() {
>    char	foo[BUFSIZ];
>
>    if(gets(foo) == NULL) return;
>    main();
>    puts(foo);
>}

This assumes you have enough memory to hold the entire file.  Also, you have to
read it all -- I wrote the program MAINLY because I wanted a QUICK way to scan
backwards.
-- 
UUCP:	...!seismo!mcvax!ukc!dcl-cs!stephen
DARPA:	stephen%lancs.comp@ucl-cs	| Post: University of Lancaster,
JANET:	stephen@uk.ac.lancs.comp	|	Department of Computing,
Phone:	+44 524 65201 Ext. 4599		|	Bailrigg, Lancaster, UK.
Project:Alvey ECLIPSE Distribution	|	LA1 4YR

dave@lsuc.UUCP (David Sherman) (09/03/85)

g/^/.m0
-- 
{  ihnp4!utzoo  pesnta  utcs  hcr  decvax!utcsri  }  !lsuc!dave

ecl@mtgzz.UUCP (e.c.leeper) (09/06/85)

What's wrong with:
	pr -n -t file | sort -nr | sed -e 's/[ 0-9]*	//'

					Evelyn C. Leeper
					...ihnp4!mtgzz!ecl

storm@diku.UUCP (Kim Fabricius Storm) (09/08/85)

In article <1124@mtgzz.UUCP> ecl@mtgzz.UUCP (e.c.leeper) writes:
>What's wrong with:
>	pr -n -t file | sort -nr | sed -e 's/[ 0-9]*	//'

Nothing except that for large files (some uucp logs are > Mbyte) it
this takes time.  I am very greatful for the FAST revfile program, which
I have been missing for a long time. 
  Revfile solves a REAL problem, while your (and others) shortways are
pretty, but also pretty useless.  I also prefer a VAX running UNIX to
a Turing machine even though the latter is all that is really needed
to do my calculations.  And C is better (or at least more structured)
than assembler, or what?
  I welcome any program, that solves my problems faster that the
standard tools.  My time is more valuable than your principles!

--
Kim F. Storm, Institute of Datalogy, U of Copenhagen, Denmark.