How can i reverse a line in a file in Order

Example :

Input file :

123
500
1000
LOAN
GOD
10000
01000

Output Format:

321
005
0001
NAOL
DOG
00001
00010
link|improve this question
Note: I voted to close as "belongs on SuperUser", but it would be even more well-suited for unix.stackexchange.com – Jörg W Mittag Sep 17 '10 at 20:41
feedback

migrated from stackoverflow.com Sep 19 '10 at 18:05

This question came from our site for professional and enthusiast programmers.

5 Answers

Use rev(1).

link|improve this answer
feedback
perl -lne 'print scalar reverse' < my_file.dat
link|improve this answer
feedback

There is no simple command to do that in the Single Unix Specification. If, however, you are able to go beyond what Unix provides, you can install rev or tac. In fact, one of those might very well already be installed on your system, despite the fact that they are not part of Unix.

Obviously, since they are not part of Unix, you should never depend on them being there.

link|improve this answer
feedback

perl -n -e "print reverse split //, $_"

link|improve this answer
feedback

You can use the tac command:

tac inputFile > outFile 

TAC(1)

NAME
       tac - concatenate and print files in reverse

SYNOPSIS
       tac [OPTION]... [FILE]...

DESCRIPTION
       Write each FILE to standard output, last line first.  With no FILE, or when FILE is -, read standard input.
link|improve this answer
feedback

Your Answer

 
or
required, but never shown