The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Reverse Arrange File The One UNIX for Dummies Questions & Answers 4 06-13-2007 08:57 AM
Need to read a file in reverse scorreg Shell Programming and Scripting 5 03-01-2006 08:14 PM
Creating file contents using contents of another file ReV Shell Programming and Scripting 21 02-24-2006 06:25 AM
sort a file in reverse order frustrated1 Shell Programming and Scripting 11 09-21-2005 12:41 PM
reverse lookup file problem Westy564 IP Networking 2 01-09-2004 10:55 AM

Reply
 
LinkBack Thread Tools Display Modes
  #8 (permalink)  
Old 06-05-2007
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,999
attached is a compilation of different methods.
Attached Files
File Type: txt reverseFile.txt (6.4 KB, 28 views)
Reply With Quote
Forum Sponsor
  #9 (permalink)  
Old 06-06-2007
praveenkumar_l's Avatar
Registered User
 

Join Date: May 2007
Posts: 36
Quote:
Originally Posted by aajan
Hi Guys,
Am new to this forum .... And also to shell scripting

I need a k-shell script to reverse the contents of a file...

Please come up with the solutions...

With regards,
Anand
By reverse, you mean character by character or line by line?
Reply With Quote
  #10 (permalink)  
Old 05-16-2008
Registered User
 

Join Date: Jun 2006
Posts: 154
Try playing with the -r flag on tail.
Reply With Quote
  #11 (permalink)  
Old 05-17-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,111
Just out of curiosity, you can use shell constructs for this, too.

Code:
#!/bin/sh

tac () {
  local line
  if read line; then
    tac
    printf '%s\n' "$line"
  fi
}

for f; do
  tac <"$f"
done
ksh could use print instead of printf; tested with bash. (Using echo is not very robust, but would be compatible even with the earliest Bourne shells. But then, local is a fairly recent addition, isn't it?)
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:14 PM.


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

Content Relevant URLs by vBSEO 3.2.0