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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How can i read a non text file in unix - ELF-64 executable object file - IA64 alexcol UNIX for Advanced & Expert Users 8 11-07-2008 08:56 AM
Scanning file backwards tekster757 UNIX for Advanced & Expert Users 2 09-21-2007 06:07 PM
Post Shell programming: Question about source a file and read data from the file ccwq Shell Programming and Scripting 3 08-04-2007 11:28 PM
ML level went backwards? pschlesinger AIX 1 08-09-2006 06:12 PM
How to read specific lines in a bulk file using C file Programming rajan_ka1 High Level Programming 10 11-10-2005 03:29 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 09-28-2007
bluemoon1 bluemoon1 is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 53
read file backwards

Assume file1 contains a list of strings.
My first script is scanning the file and deals with the lines with a certain patern in it:

grep 'somepatern' file1 \
while read LINE ; do
doSomethingAboutIt
done

Now, I need a second script that deals with the same lines (& do something differently) but in the opposite order; the last line found in the file with that patern shuld be handled first.

Please help me. Thanks so much!!!

Last edited by bluemoon1; 09-28-2007 at 12:36 AM.. Reason: typo
  #2 (permalink)  
Old 09-28-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
You could generate a file with all the lines reversed by using something like


Code:
cat </dev/null >output
while read N
do
     echo "$N" >output.tmp
     cat output >>output.tmp
     mv output.tmp output
done

  #3 (permalink)  
Old 09-28-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
Hey, there's a new approach. For some other solutions see: sort a file in reverse order
  #4 (permalink)  
Old 09-28-2007
bluemoon1 bluemoon1 is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 53
Thanks you so much, Porter & Perderabo!!
Yes, this will do (& is cute too;-)
tail -r file1
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 07:58 AM.


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