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
searching and storing unknown number of lines based on the string with a condition swamymns Shell Programming and Scripting 7 05-13-2008 01:02 AM
replacing new lines in all files of a directory containing old lines rooster005 Shell Programming and Scripting 1 03-25-2008 03:38 PM
How to count lines - ignoring blank lines and commented lines kthatch UNIX for Dummies Questions & Answers 6 05-25-2007 01:21 AM
Strip 3 header lines and 4 trailer lines ganesh123 Shell Programming and Scripting 9 03-10-2007 05:15 PM
need help appending lines/combining lines within a file... mr_manny Shell Programming and Scripting 2 01-06-2006 06:45 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-25-2006
miechu miechu is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 10
sed searching across lines

hi,

i'm making now a bash script, that runs some compiler... i want to take only errors form its output eg:

output:
Code:
bla bla bla
...
erros is 1324546
the bla bla bla 

bla bla bla...
...
and i want to get only
Code:
erros is 1324546
the bla bla bla
i've managed to do something like this:
Code:
cat errors_file | sed -n "N;s/errors.*\n/&/P"
but i don't know how to do something like (.*\n)* how can this be done?
  #2 (permalink)  
Old 09-25-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,416
Try this:
Code:
sed -n '/erros is/{N;p;}' errors_file
Jean-Pierre.
  #3 (permalink)  
Old 09-25-2006
miechu miechu is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 10
this is not exactly what i want... becouse i don't know how many lines error will have... all i know it beigns with:"errors is" and ends with ^$

#edited

and can you explain what your command does? as i understand it it will print out the maching line and the one follwing it... but why this strange syntax? why do you do some {} at the end? where is s/?

Last edited by miechu; 09-25-2006 at 05:13 AM..
  #4 (permalink)  
Old 09-25-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,416
Quote:
this is not exactly what i want... becouse i don't know how many lines error will have... all i know it beigns with:"errors is" and ends with ^$
In that case :
Code:
sed -n '/erros is/,/^$/p' errors_file
Quote:
and can you explain what your command does? as i understand it it will print out the maching line and the one follwing it... but why this strange syntax? why do you do some {} at the end? where is s/?
/error is/{ ... }
Select lines that contains 'erros is' and execute commands '...'
N;p
Append next line to current line and print the whole

Jean-Pierre.
  #5 (permalink)  
Old 09-25-2006
miechu miechu is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 10
cooooooooool this is great can you explain me this command?

btw. big, big biiiiiiiiig thanks
  #6 (permalink)  
Old 09-25-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,416
From sed man page :
Quote:
A command line with two addresses separated by commas selects the entire
range from the first line that matches the first address through the next
line that matches the second. (If the second address is a number less than
or equal to the line number first selected, only one line is selected.)
Thereafter, the process is repeated, looking again for the first address.
/erros is/,/^$/p
First line contains 'erros is' and last line is empty.


Jean-Pierre.
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 10:11 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