How to remove paragraphs with specific text from my text file?

18 views
Skip to first unread message

Igor

unread,
Apr 14, 2021, 8:13:14 AM4/14/21
to vim_use

Hi,
I have 130 thousand lines of output file.
- Each output is in separate paragraph.
- Each paragraph has at least two or more rows.
I would like to remove all paragraphs that ends with (this text is alway last line in paragraph):
DB20000I  The SQL command completed successfully.

Or simpler: I want to keep all paragraphs that has "SQLSTATE=" (without double quotes) in the last line.

Sample output file:

xxx xxxxxx
DB20000I  The SQL command completed successfully.

xxx xxxxxx
xxx xxxxxx
DB20000I  The SQL command completed successfully.

xx xxxxxxxx xxxxxx xx xxxxxx
xxxxx xx xxxxx yyyyyyy yyyyy. SQLSTATE=01550

xx xxxxxx
SQLSTATE=42704

xx xxxxxx
xx xxx xxxxxxx
xxx xxxxxx
DB20000I  The SQL command completed successfully.


xxx xxxxxx
DB20000I  The SQL command completed successfully.



I want to remove:

xxx xxxxxx
DB20000I  The SQL command completed successfully.

xxx xxxxxx
xxx xxxxxx
DB20000I  The SQL command completed successfully.

xx xxxxxx
xx xxx xxxxxxx
xxx xxxxxx
DB20000I  The SQL command completed successfully.

xxx xxxxxx
DB20000I  The SQL command completed successfully.


I want to keep:

xx xxxxxxxx xxxxxx xx xxxxxx
xxxxx xx xxxxx yyyyyyy yyyyy. SQLSTATE=01550

xx xxxxxx
SQLSTATE=42704


How to accomplish this with vim?

Salman Halim

unread,
Apr 14, 2021, 8:30:42 AM4/14/21
to Vim Users
Try (untested):

:g/SQL command completed successfully/normal! dap

Salman

--

Salman

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/362a2060-58a7-465a-8f7c-d837717f3347n%40googlegroups.com.

rwmit...@gmail.com

unread,
Apr 14, 2021, 8:42:51 AM4/14/21
to vim_use

Tim Chase

unread,
Apr 14, 2021, 8:52:21 AM4/14/21
to Igor, vim...@googlegroups.com
On 2021-04-14 05:13, Igor wrote:
> I have 130 thousand lines of output file.
> - Each output is in separate paragraph.
> - Each paragraph has at least two or more rows.
> I would like to remove all paragraphs that ends with (this text is
> alway last line in paragraph):
> DB20000I The SQL command completed successfully.

To delete the paragraphs with this text:

:g/DB20000I The SQL command completed successfully/'{,'}d

should do the trick

-tim



aro...@vex.net

unread,
Apr 14, 2021, 9:35:18 AM4/14/21
to vim...@googlegroups.com
> igo...@gmail.com stated

> I have 130 thousand lines of output file.
> - Each output is in separate paragraph.
> - Each paragraph has at least two or more rows.
> &c

That was a model example of a problem statement; clear illustration of
sample input and the desired output.

I'd be inclined to go with the awk/sed type solutions, if only to make a
clear series of steps, keeping an original file intact, at least until
it's clear that it is no longer required.


c.willis111

unread,
Apr 14, 2021, 10:03:53 AM4/14/21
to vim...@googlegroups.com
Hi Igor


assuming paragraph means there are empty lines between the paragraphs, awk uses the empty string as a record separator specifying the same. So


gawk /SQLSTATE=/ RS= ORS=\n\n datafile > a


creates a file in the same format, but with only those paragraphs containing SQLSTATE= . Not even the equals sign is a metacaracter, so no escaping is needed. When redirecting output, I use the convention that a is a transitory file, that can always be overwritten. If I wish to keep it, I then rename it.


As far as I can see this will work in an MS command window, or Unix versions. If you don't have an awk in the system gnu awk is downloadable. It is an executable. It relies on no dlls.


regards - Chris

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/58f2565c67921d04b06cb2e025d3951c.squirrel%40webmail.vybenetworks.com.
Reply all
Reply to author
Forward
0 new messages