Monday, March 22, 2010

To reverse a file

#If @ is used anywhere in the file to be reversed, use any other
special character that is not used 

ctr=`cat filename|wc -l `
line=`sed 's/$/@/g' filename |tr -d "\n"`
while test $ctr -ne 0
do
        echo $line|cut -d"@" -f$ctr
        ctr=`expr $ctr - 1`
done
 
-----------------------------------------------------------------------
nl -ba FILE | sort -nr | cut -f2-

No comments:

Post a Comment