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
How to reverse the contents of a file? aajan UNIX for Advanced & Expert Users 10 05-17-2008 08:03 AM
How reverse cut or read rows of lines doer Shell Programming and Scripting 16 07-18-2007 11:26 PM
Reverse Arrange File The One UNIX for Dummies Questions & Answers 4 06-13-2007 08:57 AM
sort a file in reverse order frustrated1 Shell Programming and Scripting 11 09-21-2005 12:41 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-01-2006
Registered User
 

Join Date: Mar 2006
Posts: 4
Need to read a file in reverse

I have to extract data from a text file which is huge in size >>10GB.
ie between two strings. If I do an ordinary sed it takes forever to come out. I was wondering if there was anyway to do the entire process in reverse and on finding the relevant string is there any way to break out of the search..
Reply With Quote
Forum Sponsor
  #2  
Old 03-01-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
reading a file in reverse,

Code:
# !/usr/bin/ksh

linecnt=`wc -l file | awk '{print $1}'`

while [ $linecnt -ge 1 ]
do
sed -n "$linecnt"p file
linecnt=$(($linecnt - 1))
done

exit 0
Reply With Quote
  #3  
Old 03-01-2006
Registered User
 

Join Date: Mar 2006
Posts: 4
thanks man

thanks man!!
Reply With Quote
  #4  
Old 03-01-2006
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Just for info: If you have GNU coreutils installed, you'll find the tac utility (reversed cat ) does the job of reading a file from bottom to top. But this won't find your match and break out for you

Cheers
ZB
Reply With Quote
  #5  
Old 03-01-2006
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
From "HANDY ONE-LINERS FOR SED" ...
Code:
# reverse order of lines (emulates "tac")
 sed '1!G;h;$!d'               # method 1
 sed -n '1!G;h;$p'             # method 2
Reply With Quote
  #6  
Old 03-01-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,698
Similiar replies to a similiar post - sort a file in reverse order. I wonder how many use the search feature of the forum.
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 11:03 PM.


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