The UNIX and Linux Forums  


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
Need help in sed command (adding a blank line btw each block generated by pattern) frozensmilz Shell Programming and Scripting 2 01-08-2009 12:12 AM
Adding a block to the file ROOZ Shell Programming and Scripting 4 08-20-2008 05:34 PM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 10:24 AM
Adding default search path for CPP boyanov UNIX for Dummies Questions & Answers 1 09-10-2007 02:46 AM
Search/replace using visual block Manan UNIX for Dummies Questions & Answers 0 12-21-2006 03:16 AM

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 01-21-2009
frozensmilz's Avatar
frozensmilz frozensmilz is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 28
Need help in sed: adding a line after each search block

Hi friends,

I have written script that will search & display the block of sql statement. Since there are many blocks of sql statement i am finding it difficult to distinguish between them. The below is the sed command & its result

exec sql
abc
abc
abc
aaaaaa;
exec sql
abc
abc
abc
aaaaaa;
eeeeeeeeeee
eeeeeeeeeee
exec sql
abc
abc
abc
aaaaaa;

using "exec sql" as begining & ";" as ending

sed -n "/exec sql/,/;/p" $srcCode


Result will be

exec sql
abc
abc
abc
aaaaaa;
exec sql
abc
abc
abc
aaaaaa;
exec sql
abc
abc
abc
aaaaaa;

I would like the result displayed as

exec sql
abc
abc
abc
aaaaaa;
---------------------
exec sql
abc
abc
abc
aaaaaa;
---------------------
exec sql
abc
abc
abc
aaaaaa;
---------------------

Kindly help me with this situation. Thanks.
  #2 (permalink)  
Old 01-21-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,289
Code:
sed '/;$/a\---------------------' infile
Edit:
I just realize that I answered a bit fast. Your sed statement gives and error when I use it. On your second output all lines with those multiple "e"s are gone.
From your description I didn't even see that you wanted to remove those lines.
If the statement above isn't what you want, best just print simple input and output.

Last edited by zaxxon; 01-21-2009 at 04:54 AM.. Reason: added comment
  #3 (permalink)  
Old 01-21-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,322
Quote:
Originally Posted by zaxxon View Post
I just realize that I answered a bit fast. Your sed statement gives and error when I use it. On your second output all lines with those multiple "e"s are gone.
In that case you can try this:

Code:
awk '/exec/{p=1}/;$/{;print;print "-----------";p=0}p' file
Regards
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:17 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