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
removing certain paragraphs for matching patterns kaushys Shell Programming and Scripting 7 08-19-2008 03:32 PM
how to filter out some paragraphs in a file cnlhap Shell Programming and Scripting 7 08-19-2008 03:03 PM
Using sed to remove paragraphs with variables BlueberryPickle UNIX for Dummies Questions & Answers 1 07-03-2008 09:46 AM
how to sort paragraphs by date within a file nabmufti Shell Programming and Scripting 1 02-13-2008 05:33 PM
fetching a web page in C rayne High Level Programming 4 08-08-2007 09:39 PM

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 02-02-2009
ipat ipat is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 2
fetching paragraphs with SED

hi,
i am a SED newbie and i need some help. i have a log file as shown below. and i want to search specific Error Code, and fetch the whole paragraph.

[2009-02-01 15:42:51,630] ...
[2009-02-01 16:52:51,683] ...
.................
....ErrCode...
.................
[2009-02-01 17:49:33,686] ...
[2009-02-01 17:59:00,000] ...
[2009-02-01 18:52:50,000] ...
.................
....ErrCode...





let's say, i want to search "ErrCode" and it will show me that. how can i do this with SED :

[2009-02-02 16:52:51,683] ...
.................
....ErrCode...
.................
[2009-02-01 18:52:50,000] ...
.................
....ErrCode...





thanks..
  #2 (permalink)  
Old 02-02-2009
quirkasaurus's Avatar
quirkasaurus quirkasaurus is offline
Registered User
  
 

Join Date: Jan 2009
Location: canton, michigan
Posts: 373
You'll need a beginning and ending paragraph search string.
This may be easier in awk, also....

But try:

Code:
sed -n '/first_string/,/second_string/p' file_in
  #3 (permalink)  
Old 02-02-2009
angheloko's Avatar
angheloko angheloko is offline
Registered User
  
 

Join Date: Jul 2008
Location: Philippines
Posts: 125
If your "paragraphs" are separated by blank lines:

Code:
sed -e '/./{H;$!d;}' -e 'x;/ErrCode/!d;'
(reference: http://sed.sourceforge.net/sed1line.txt. Very good reference for sed )
  #4 (permalink)  
Old 02-02-2009
ipat ipat is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 2
i mean timestamps with "paragraphs". this is an error log as you guess.
  #5 (permalink)  
Old 02-02-2009
quirkasaurus's Avatar
quirkasaurus quirkasaurus is offline
Registered User
  
 

Join Date: Jan 2009
Location: canton, michigan
Posts: 373
Input file looks like:

Code:
ant 1
bat 2
cat 3
dog 4
emu 5
fox 6
ant 7
bat 8
cat 9
dog 10
emu 11
fox 12
ant 13
bat 14
cat 15
dog 16
emu 17
fox 18
ant 19
bat 20
cat 21
dog 22
emu 23
fox 24
Substitute 'dog' and 'fox' with your search strings:

Code:


cat a |
awk '
  /dog/{ print_ind = 1; }
  { if ( print_ind == 1 ){ print; }}
  /fox/{ print_ind = 0; }'

Last edited by quirkasaurus; 02-02-2009 at 11:40 AM.. Reason: one too many print statements.
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 11:06 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