Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding ; on the end of a paragraph

Status
Not open for further replies.

atojaf

Programmer
Mar 7, 2006
18
US
Hello,

COuld you please tell me how to add ; at the end of each paragraph. Can I use sed? if so what is the syntax.

thanks very much.
 
What is your meaning of a paragraph ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
it's actually an Oracle script. I want to add ; (semicolon) at the end of the script.
 
sed '$s!$!;!' /path/to/input > output.sql

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for your help PHV. I am sorry I should have been more specific. here is what I am trying to do:

i have several blocks of sql script that I want to run at the same time . So at the end of each block, I want to append a ; . These sripts are all located in the same file.

ie.

codsdlakfjsaddddddlfklajsdflkjasklfja
sadjflkdasjflk;sadflkjasldjflkasjdflksdja
aksljfdsajdflkjsadfkjasldfjklsf;<<<<<<


kljdfkjasdfljasdlfjlasdjflksdajflk
klfjlkasjflkjsadflkjasdlfjlasdjflksdaj
ajsdflkasjdfljasdlfjlasdjflkjsadflkjasdljf
klsjfdjsdfljsaldfjlsakdasjflksajdlsdajfj;<<<<<<<

lkjasfdkljsadflkjsalkfjlsadjflksdajfjsdfa
dsfasjdfasdfkjasdjfkldsf
klasjfdlkasdjlksdjaflkdsjflkjdsafkl;<<<<<<<<<
 
So, again, what is a block delimiter for you ?
You may try this:
awk 'BEGIN{FS=RS="";ORS=";\n"}1' /path/to/input > output.sql

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,
I'd say - to get closer to the 'paragraph' definition:
Code:
awk 'BEGIN{FS=RS="";ORS=";\n[COLOR=red]\n[/color]"}1' /path/to/input > output.sql

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Good point Vlad.
But empty lines aren't necessary in a SQL script.
 
PHV,
if the empty lines are NOT in the SAL script then the meaning of the 'paragraph' is somewhat vague and therefore the 'RS=""' is not the right solution.

there seems to be multiple 'empty lines' in the OPs sample and I thought that what separated 'paragraphs'.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hi

Just a notice. In an SQL script you do not need to have the semicolon ( ; ) in the same line with the command. So the easy & fast way is to just replace the "paragraph" separator empty line with the semicolon.

Another way, usefull if you have no empty lines, is to add a semicolon in front of lines which begins with an SQL command.
Code:
sed '/^insert\|^delete\|^update/s/^/;/' /input/file
Of course, the above solutions are only usefull in case you need the resulted SQL for execute it and not for further editing.

Feherke.
 
thanks for the input guys. Here is what I got:

when I executed these scripts:
sed '/^insert\|^delete\|^update/s/^;/' source , I got this message>>>>>
"/^insert\|^delete\|^upda.......":unterminated substitute in regular expression error message

also when I executed this:
awk 'BEGIN{FS=RS="";ORS=";\n\n"}1' /path/to/input > output.sql
I got this message>>>> awk: input record ' oracle script here blah blah blah...........' too long; try -mr n

by the way PHV, block delimeters are just empty lines. thanks everyone.....


 
if you're under Solaris, try using 'nawk' instead of plain old 'awk'.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
and in the sed solution you missed a '/' right before the ';'

Perhaps in addition you need to escape the ';' like in

sed '/^insert\|^delete\|^update/s/^/\;/' /input/file


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top