2

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

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

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

12

Use rev(1).

2
perl -lne 'print scalar reverse' < my_file.dat
2

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.
  • This is the simplest solution. – Brad Dausses Apr 9 '17 at 4:57
1

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.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy