Pages

Reversing the contents of a file

The command cat is used to view the contents of a file with out opening it, the contents are displayes from top to bottom in the usual way. In case you want to view the contents in the reverse that is from last line to first here are a few ways to do it.

Let us say we have a file named test with the following contents

test :



1. tac

The command tac takes a filename as input and displays the contetns in the bottom up fashion.



2. Using awk :

The following awk script takes a file name as input and displays the same in the reverse order .



3. Using sed :

The following sed script takes a file name as input and reveres the contents, displaying it from bottomt to top.



No comments:

Post a Comment