shell pipeline to reverse the order of lines.

D'Arcy J.M. Cain darcy at druid.uucp
Fri Mar 1 00:46:28 AEST 1991


In article <1991Feb27.010612.25618 at agate.berkeley.edu> Paul Vojta writes:
>In article <1991Feb26.025903.5850 at NCoast.ORG> allbery at ncoast.ORG (Brandon S. Allbery KB8JRR) writes:
>>I don't understand what's wrong with
>>	nl | sort -nr | cut -f2-
>What's wrong with
>	tail -r

It isn't available on all systems.

I once wrote a C program to do this.  Here is the code slightly modified
to remove some extra processing I needed for that application.  Note that
long lines could be handled using malloc/realloc but this worked for my
purposes at the time and it was fast.  It also didn't take more than 5
minutes to write, even with the extra stuff I needed at the time.

/* flip.c */
#include	<stdio.h>
void	flip(void)
{
	char	entry[128];

	if (gets(entry))
	{
		flip();
		printf("%s\n", entry);
	}
}

int		main(void)
{
	flip();
	return(0);
}

-- 
D'Arcy J.M. Cain (darcy at druid)     |
D'Arcy Cain Consulting             |   There's no government
West Hill, Ontario, Canada         |   like no government!
+1 416 281 6094                    |



More information about the Alt.sources.d mailing list