LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-09-2013, 02:40 PM   #1
dmesserly
LQ Newbie
 
Registered: Apr 2013
Posts: 6

Rep: Reputation: Disabled
awk print pattern match line and subsequent


Data looks like this:

blahblah
blahblah
pattern data data data
data data data
data data data
pattern data data data
data data data
...
blahblah
blahblah

What I would like to do is match on pattern, print that line and the subsequent data lines, then do not print 'blahblah' to EOF.

If someone can show me how to do this with awk, I would appreciate it!
 
Old 04-09-2013, 04:20 PM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
This is a natural job for sed.

sed -n -e '/text_matching_line_to_quit_on/q' -e '/text_matching_first_line_to_show/,$p' filename
 
1 members found this post helpful.
Old 04-09-2013, 05:27 PM   #3
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
With this InFile ...
Code:
blahblah
blahblah
pattern data data data
data data data
data data data
pattern data data data
data data data
blahblah
blahblah
...this awk ...
Code:
awk '{if ($1~"pattern") patseen=1;
      if (patseen && $1!~"blah") print}' $InFile
... produced this result ...
Code:
pattern data data data
data data data
data data data
pattern data data data
data data data
Daniel B. Martin

Last edited by danielbmartin; 04-09-2013 at 05:56 PM. Reason: Tighten the code, slightly
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] SED/AWK - Delete all lines until empty line is found after pattern match vikas027 Programming 13 03-28-2012 08:33 AM
[SOLVED] sed/awk to print every before line that pattern match niharikaananth Linux - Newbie 10 02-22-2012 10:47 PM
[SOLVED] AWK: match multiple strings in the file, print 1 when match and 0 when not cristalp Programming 12 11-15-2011 10:18 AM
[SOLVED] Awk - How to print match instead of whole line protocol Linux - General 8 10-24-2011 01:30 PM
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 06:17 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration