Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
share|improve this question

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

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

5 Answers 5

Use rev(1).

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

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.

share|improve this answer

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.
share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.