Search This Blog

Saturday, March 12, 2011

Funny way to print lines in reverse order

This is completely something you need see at least once in your live to know what you never should do ;).

The complete code examples bellow are taken from the original post at Print lines in reverse order

The recommended way:
$ tac file

The more funny way to achieve the same result ;)
$ cat -n file | sort -k1,1rn | cut -f 2-

$ perl -e 'print reverse <>' file

#example3; sorry, this one is not a one line command
$ i=0
$ while IFS= read -r arr[i]; do ((i++)); done < file
$ for((j=i-1;j>=0;j--)); do printf "%s\n" "${arr[$j]}"; done

No comments:

Post a Comment