The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Append (cat) to beginning of file ? CBZ Shell Programming and Scripting 8 02-19-2008 01:26 AM
Add text to beginning of file donkey Shell Programming and Scripting 2 08-24-2007 07:24 AM
input a line at the beginning of every file in a directory? Terrible Shell Programming and Scripting 6 08-16-2006 06:42 AM
Adding a character in the beginning of every line in a .dat file Cool Coder Shell Programming and Scripting 2 12-22-2005 06:47 AM
the very beginning Mudrack UNIX for Dummies Questions & Answers 6 03-24-2005 05:46 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-23-2001
jpprial jpprial is offline
Registered User
  
 

Join Date: Feb 2001
Location: San Francisco
Posts: 30
Is there an option, for cat, head, tail, or is there any way, to display a file from last line to first? For example, my file
looks like this:

aaaa
bbbb
cccc
eeee

and I would like to print or display it like this:

eeee
cccc
bbbb
aaaa

thanks
  #2 (permalink)  
Old 03-23-2001
98_1LE 98_1LE is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2000
Location: Greater Dallas area
Posts: 405
If file contains;
aaaa
bbbb
cccc
dddd


Then
Code:
sort -r file
will output;
dddd
cccc
bbbb
aaaa
  #3 (permalink)  
Old 03-23-2001
PxT's Avatar
PxT PxT is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
Quote:
sort -r file

This will only work if the original file is in alphabetical order. The proper solution is to use 'tac' (which is the opposite of 'cat').
  #4 (permalink)  
Old 03-30-2001
mib mib is offline
Registered User
  
 

Join Date: Jan 2001
Location: Calicut
Posts: 228
or cat file | perl -e 'print reverse <>'

  #5 (permalink)  
Old 03-30-2001
PxT's Avatar
PxT PxT is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
Quote:
cat file | perl -e 'print reverse <>'
<A HREF="http://www.ling.helsinki.fi/~reriksso/unix/award.html">UUOC</A>. Just do perl -e 'print reverse <>' file

However, the down side to the perl method is that the whole file must be read into memory. Could be a memory-hog for extremely large files. I believe 'tac' uses seek to read through the file, so that you can view files of arbitrary size. Usually not a problem though. The perl method is good if you dont have 'tac' installed.
  #6 (permalink)  
Old 03-31-2001
mib mib is offline
Registered User
  
 

Join Date: Jan 2001
Location: Calicut
Posts: 228
Yes, use of cat there shows useless usage of cat.

Thanks for pinch on nose warning PxT.




Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:03 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0