Librenix
Headlines | Linux | Apps | Coding | BSD | Admin | News
Information for Linux System Administration 

Eight Ways to Reverse a File

Up
vote
Down

Coming up with eight reasons why you might need to reverse a file is left as an exercise for the reader...
We can use a utility that supports arrays, including the shell. Read the file into an array and index it in reverse order. This is an awk solution:

awk '{ a[NR]=$0 } END { for(i=NR; i; --i) print a[i] } ' datafile

The awk internal number of records variable (NR) increments as each line of the data file is read. Store each line in an array indexed by NR, and at the end, loop through the array in reverse order.
 read more | mail this link | score:8096 | -Ray, April 29, 2005
More articles...

Abstract Art Prints for Sale

news headlines

You may now buy the SlateBook x2 for $479

Selling Palm to HP was a waste

ROSA Desktop Fresh LXDE alpha preview

Riak Cloud Storage released under Apache 2 license

Ubuntu for smartphones

Backdoor on Verizon routers?

 

Firefox sidebar

Site map

Site info

News feed

Features

Login
(to post)

Search

 
Articles are owned by their authors.   © 2000-2012 Ray Yeargin