How to perform join of lines on many rows following simple rules?

11 views
Skip to first unread message

Igor

unread,
May 21, 2021, 7:46:26 AM5/21/21
to vim_use

I have the following data:

YYY AAA
YYY BBB
CCCCC
YYY CCC
DDDD
EEEE
(and few hundreds rows)

Rules:
1. First line always starts with YYY.
2. Line should start with YYY.
3. All lines that do not start with YYY must be joined into previous lines.

Above sample data should become:

YYY AAA
YYY BBB CCCCC
YYY CCC DDDD EEEE


How to accomplish transformation?
Regards

c.willis111

unread,
May 21, 2021, 8:04:02 AM5/21/21
to vim...@googlegroups.com
--

Hi Igor

how about:

:g!/^YYY/-j

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 unsub...@googlegroups.com">vim_use+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/8152ff6a-9bb8-4c0b-91a5-9df523d70562n%40googlegroups.com.

Mikhail Velikikh

unread,
May 21, 2021, 8:22:26 AM5/21/21
to vim...@googlegroups.com
Hi,

How about:
:%s/\n\(YYY\)\@!/ \1/g

Explanation:
\n - new line
\(YYY\)\@! - not followed by YYY
/ \1/ - replace with a space plus the line



--
--
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.
Reply all
Reply to author
Forward
0 new messages