Need help in sed command (adding a blank line btw each block generated by pattern)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help in sed command (adding a blank line btw each block generated by pattern)
# 1  
Old 01-01-2009
Need help in sed command (adding a blank line btw each block generated by pattern)

Hello friends,

I have a C source code containing sql statements. I use the following sed command to print all the sql blocks in the source code....

sed -n "/exec sql/,/;/p" Sample.cpp

The above sed command will print the sql blocks based on the pattern "exec sql" & ";" (since most of them start with "exec" & ends in ";") & the output will look like this (with no ">>>>")

1>>>> exec sql select pqxQrn,
pqxPmeOldQcl
into :qrn, :qxt, :cuk, :cln, :pqxTdd,
:pmeOldQcl indicator :pmeOldQclInd
from pqx
1>>>>where pqxDno = :dno;
2>>>>exec sql select qcfQcl into :oldQcl from qcf
1>>>> where qcfCuk = :cuk;
2>>>> exec sql select cufCid
into :cid
from cuf
1>>>>where cufCuk = :cuk;
2>>>> exec sql select clrChief
into :chief
from clr
1>>>> where clrCln = :cln;
2>>>> exec sql select count(*) into :cnt from pqx
1>>>> where pqxQrn < :qrn;
2>>>> exec sql declare xqxPmeCur cursor for
select pqxQrn
from pqx
where pqxQxt = QXT_PME and
pqxCuk = :cuk and
pqxPmeDno = :dno and
1>>>> pqxTdd = :pqxTdd;
2>>>> exec sql open xqxPmeCur;

I would like to insert a space in between each sql blocks (between "1>>>>" & "2>>>>").....so that it is more readable. Kindly help....& thanks in advance.....
# 2  
Old 01-01-2009
Somthing like this should work:
Code:
sed -e '/exec sql/,/;/!d' -e '/;/G'

# 3  
Old 01-08-2009
Need help in sed command [ Adding a dividing line between each pattern block ]

Thanks for the help,

How can i add a dividing line like "------------------" between each pattern block using sed ?

Thanks in advance,
SmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

2. UNIX for Dummies Questions & Answers

Sed: Adding new line after matching pattern

Hi I just wanted to add a new line after every matching pattern: The method doing this doesn't matter, however, I have been using sed and this is what I tried doing, knowing that I am a bit off: sed 'Wf a\'/n'/g' Basically, I want to add a new line after occurrence of Wf. After the line Wf... (5 Replies)
Discussion started by: MIA651
5 Replies

3. Shell Programming and Scripting

Replace a pattern in a file with a generated number using sed or awk

my file has thousands of line but let me show what i want to achieve... here is one line from that file cat fileName.txt (2,'','user3002,user3003','USER_DATA_SINGLE',1,0,0,'BACKUP',2,NULL,0,450,NULL,NULL,'','2011-05-10... (13 Replies)
Discussion started by: vivek d r
13 Replies

4. Shell Programming and Scripting

sed adding a blank line

I use the following as part of a script to correct for a faulty hostname file. # get the domain name read -r thehostname < /etc/hostname dom="$(echo $thehostname | cut -d'.' -f2)" numchar=${#dom} if then echo "It appears as though the hostname is not correctly set." echo "Hostname has... (5 Replies)
Discussion started by: bugeye
5 Replies

5. Shell Programming and Scripting

Fill the empty line by adding line before blank line

FIle A "A" 2 aa 34 3 ac 5 cd "B" 3 hu 67 4 fg 5 gy output shud be A"" 2 aa 34 "A" 3 ac 34 "A" 5 cd 34 "B" 3 hu 67 "B" 4 fg 67 "B" 5 gy 67 (6 Replies)
Discussion started by: cdfd123
6 Replies

6. Shell Programming and Scripting

deleting blank line and row containing certain words in single sed command

Hi Is it possible to do the following in a single command /usr/xpg4/bin/sed -e '/rows selected/d' /aemu/CALLAUTO/callauto.txt > /aemu/CALLAUTO/callautonew.txt /usr/xpg4/bin/sed -e '/^$/d' /aemu/CALLAUTO/callautonew.txt > /aemu/CALLAUTO/callauto_new.txt exit (1 Reply)
Discussion started by: aemunathan
1 Replies

7. Shell Programming and Scripting

SED - adding blank line after each Range Match

the following range matching works great but i wish to add a blank line after each range result set... which i've tried and researched to no avail MY INPUT DATA: CURRENT CODE I'M USING: sed -n '/*$/,/;/p' $INPUT_FILE RESULTS I'M GETTING: RESULT I looking to... (5 Replies)
Discussion started by: danmauer
5 Replies

8. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: frozensmilz
2 Replies

9. Shell Programming and Scripting

SED - adding a new line after pattern

Hi, In files, I have a field Date Of Birth (DOB). After that line I need to add Date of Joining (DOJ) DOB:19-Apr-1981 needs to become DOB:19-Apr-1981 DOJ:20-Jun-2005 What can be a sed/perl line that can do it for me. Please note that DOB/DOJ I have in variables I am doing in a... (6 Replies)
Discussion started by: eagercyber
6 Replies

10. Solaris

adding a new line using sed command

I need to find text "A" and replace it with A B. The issue is that I need a new line between A and B. \n does not do the work. Any help would be much appreciated. Thanks, (2 Replies)
Discussion started by: ivesia
2 Replies
Login or Register to Ask a Question