On Aug 25, 12:26 pm, Marcelo Sabino <marcelo.sab...@gmail.com> wrote:
> Hi all,
> I'm having "troubles" with ER on vi. Let me explain. I have this data
>
> 03;14;Production;trombetas;Xeon;RHEL;-;PPE;-;F1-A0.3;|
>
> and I want to copy the data of third field to the last field, like this
>
> 03;14;Production;trombetas;Xeon;RHEL;-;PPE;-;F1-A0.3;|trombetas

Doubtless there will be many suggestions. There are many ways to
accomplish this. If all lines in the file are of the same format, some
solutions will be easier, if only a few lines, other solutions. If the
fields are fixed length, or of the first fields are always of the same
format, or restricted to certain character strings, another set of
solutions may present themselves.

That said, one regex that will identify the field (fourth field base
1, field number 3 base 0) you used in your example, combined with a
substitute command that may be used for one line or for a selection of
lines, is:

 s/.\{-};.\{-};.\{-};\(.\{-}\);.*/\0\1/

This relies on \{-} ( :help /\{ ), which selects the shortest matching
sequence of the preceding character or character class, and substring
selection, both default (\0 for the whole pattern string) and explicit
\1 (the first substring in parentheses) ( :help :s% ).

Note that this will fail if semicolons are allowed within fields
(perhaps quoted according to the syntax of the data file), as is
allowed in a CSV file. There may be no simple solution in such a case.

--
Rik

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to