Sunday, December 10, 2017

Re: pattern for substitution including linefeed and carriage return

On 2017-12-10, Erhy wrote:
> Hello!
> I got an CSV file in which some items have more lines
> and I want to delete them. This items have also textmarkers "
> e.g.
> 30.11.2017;"Name";"Legend
> for name
> is not found";"New York";
>
> How I remove such
>
> "Legend
> for name
> is not found"
>
> with wildcards focused only on linefeeds in such items.

A pattern that will match that string is

"Legend\nfor name\nis not found"

\n matches the end-of-line marker in the Vim buffer. Vim converts
a file's end-of-line markers to its internal end-of-line markers
when it reads a file, and writes the appropriate end-of-line markers
to a file when it writes a file, according to the setting of
'fileformat', so you don't need to concern yourself with whether the
file uses LF or CR-LF at the ends of lines.

To delete all lines containing that string, you could use:

:g/"Legend\nfor name\nis not found"/.,+2d

The :g/<pattern>/d command deletes only the line at which the
pattern matches, which would delete only the line containing
'"Legend'. The .,+2 is needed to delete all three lines.

See

:help /\n
:help 'fileformat'
:help /\_.
:help :range

HTH,
Gary

--
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment