The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
linux reverse page order+duplex is not working uttamhoode UNIX for Advanced & Expert Users 0 06-02-2008 03:06 AM
reverse sort markjason Shell Programming and Scripting 3 04-09-2007 06:37 PM
Stopping Start/Stop scripts in reverse order madasafish Shell Programming and Scripting 1 08-05-2006 08:05 AM
Sort - original order .... Help olga UNIX for Dummies Questions & Answers 2 06-01-2005 05:26 AM
using sed and regex to reverse order??? urtherhoda UNIX for Dummies Questions & Answers 2 10-13-2004 07:57 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-21-2005
Registered User
 

Join Date: Aug 2003
Location: Ireland
Posts: 269
sort a file in reverse order

I a file with log entries... I want to sort it so that the last line in the file is first and the first line is last..

eg.
Sample file
1
h
a
f
8
6

After sort should look like
6
8
f
a
h
1


Is this possible?
Reply With Quote
Forum Sponsor
  #2  
Old 09-21-2005
RishiPahuja's Avatar
Registered User
 

Join Date: Apr 2005
Location: Bangalore, India
Posts: 203
Thumbs up

Code:
tail -r filename
rishi
Reply With Quote
  #3  
Old 09-21-2005
Registered User
 

Join Date: Aug 2003
Location: Ireland
Posts: 269
Its always something simple ehh.. I was playing around with sort -r but that was doing too much sorting..

Thanks for that!!!
Reply With Quote
  #4  
Old 09-21-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
Yet another way.

The actual sample file.
Code:
$ cat sample.file 
1
h
a
f
8
6
The reversed sample.file
Code:
$ tac sample.file 
6
8
f
a
h
1
vino
Reply With Quote
  #5  
Old 09-21-2005
Registered User
 

Join Date: Sep 2005
Posts: 27
I think its better to use sort itself...

sort -r <filename>

I didn't c an option " -r " with tail...
Reply With Quote
  #6  
Old 09-21-2005
RishiPahuja's Avatar
Registered User
 

Join Date: Apr 2005
Location: Bangalore, India
Posts: 203
Red face

hey vino,
tac is not available under solaris 5.8


rishi
Reply With Quote
  #7  
Old 09-21-2005
Registered User
 

Join Date: Sep 2005
Posts: 27
And as RishiPahuja has told, tail also works but with -n option

Code : tail -n filename
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:31 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0