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 > 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
Filter out lines of a cvs from values from an other file sickboy Shell Programming and Scripting 3 06-25-2008 09:50 AM
get lines with multiple values at a position deepakgang Shell Programming and Scripting 9 03-27-2008 04:23 AM
Help!! Need script to read files and add values by lines... dhuertas Shell Programming and Scripting 3 09-15-2007 11:14 PM
grab next consecutive line or lines wisher115 Shell Programming and Scripting 1 12-07-2006 08:01 AM
Search file for pattern and grab some lines before pattern frustrated1 Shell Programming and Scripting 2 12-22-2005 03:41 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-18-2008
JamesByars JamesByars is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 124
script to grab lines between two values

hi guys

say I have a file that contains

Code:
hello
world
this 
is
AAAAA
message
to
try
BBBBBB
and 
see
if
anyone
AAAAA
knows
the
answer
BBBBBB
thanks
Now I would like a script so that it will grab AAAAA and BBBBBB and everything in between and write to a new file

i.e.

I would like in my file


Code:
AAAAA
message
to
try
BBBBBB

AAAAA
knows
the
answer
BBBBBB
thanks
  #2 (permalink)  
Old 09-18-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,390
is this what you wanted.. just check..
Quote:
awk '/AAAAA/,/BBBBBB/' infile > outfile
  #3 (permalink)  
Old 09-18-2008
JamesByars JamesByars is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 124
Quote:
Originally Posted by vidyadhar85 View Post
is this what you wanted.. just check..
that is exactly what I wanted vidya, many thanks
  #4 (permalink)  
Old 09-19-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,078
Code:
awk '{
 if($0=="AAAAA")
       a=1
 if(a==1)
       print
 if($0=="BBBBBB")
 {
       print ""
      a=0
 }
}' filename
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:49 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