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
Getting the lines between last occurrence of two patterns rvz Shell Programming and Scripting 8 08-08-2008 05:32 PM
SED replace string by occurrence uttamhoode Shell Programming and Scripting 4 03-05-2008 05:04 AM
Finding nth occurrence in line and replacing it stresing UNIX for Dummies Questions & Answers 5 02-01-2008 04:56 AM
Replace second occurrence only lyoncc Shell Programming and Scripting 5 12-26-2007 11:21 PM
Grep for the same occurrence or maybe Sed hcclnoodles Shell Programming and Scripting 4 09-12-2002 12:25 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-04-2007
agibbs agibbs is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 4
awk + last occurrence

Hi,
I'm attempting to search, using awk, a pattern range in a file. Something like:
>awk '/first bit of text.../,/...last bit of text/' file
Is it possible to print only the last (or first) occurrence of the pattern range this way?
Thanks for any suggestions.
Al
  #2 (permalink)  
Old 10-04-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
from the top of my head - not easly and/or awk-natively, but:
Code:
/123/ {a=""}
# last
#/123/,/456/ {a=(a=="") ? $0 : a RS $0}

# first
/123/,/456/ {a=(a=="") ? $0 : a RS $0}
/456/ {exit}
END {
  print a
}
  #3 (permalink)  
Old 10-06-2007
agibbs agibbs is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 4
Works great, thanks!
Al
Sponsored Links
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 09:43 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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