 vote
 |
|
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.
| | |
| |
|
|