[olug] Unix Tip: ENHANCED #1576 FILE REVERSAL

Unix Guru Universe listserv at ugu.com
Thu May 15 00:08:07 UTC 2003


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

			      UNIX GURU UNIVERSE 
			         UNIX HOT TIP

			Unix Tip 1960 - May 14, 2003

		    http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


ENHANCED #1576 FILE REVERSAL

This is an enhancement to 
UNIX Tip #1576 - April 25, 2001.

The original tip is kind a 
cool, so I decided to enhance it.

I hope it's okay with the main author.

#!/bin/ksh
lns=`wc -l $1 | nawk '{ print $1 }`
{
cat $1 | awk '{ line[NR] = $0; } 
{ for (i = NR; i > 0; --i) print line[i] }'
} >> $$.temp
tail -"$lns" $$.temp
rm $$.temp

This tip generously supported by: jena_m at hotmail.com

---------------------------------------

FILE REVERSAL

For those that don't have 
the tac command, to reverse 
a file in UNIX, you could use:

cat <file-name> | awk '{ line[NR] = $0;} END
{for(i=NR;i>1;i--) print line[i] }'


This tip generously supported by: chandramohan_k at infy.com



--------------------------------------------------------------------------
To Subscribe:    http://www.ugu.com/sui/ugu/show?tip.subscribe
To Unsubscribe:  http://www.ugu.com/sui/ugu/show?tip.unsubscribe
To Submit A Tip: http://www.ugu.com/sui/ugu/show?tip.today

==========================================================================
DISCLAIMER: All UNIX HOT TIPS ARE OWNED BY THE UNIX GURU UNIVERSE AND ARE
NOT TO BE SOLD, PRINTED OR USED WITHOUT THE WRITTEN CONSENT OF THE UNIX 
GURU UNIVERSE. ALL TIPS ARE "USE AT YOUR OWN RISK". UGU  ADVISES THAT 
ALL TIPS BE TESTED IN A NON-PRODUCTION DEVELOPMENT ENVIRONMENT FIRST.

Unix Guru Universe - www.ugu.com - tips at ugu.com - Copyright 1994-2001
==========================================================================



More information about the OLUG mailing list