how to search multiple patterns and move to end

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

how to search multiple patterns and move to end

vimlover
Hello,
I have new for vim.
I have a file like

alter table a1 enable constraints xxx;

alter table b1 enable constraints xxx;

alter table c1 enable constraints xxx;
....(millions of rows...)

I know if I want to search pattern "a1", and, move the line (with this pattern) to end of file by using
:g/a1/m$

but if if want to search a couple of patterns, for example,like a1 and b1, and move to the end of files,
how can I do?


Thank you for help

Vimlover



Reply | Threaded
Open this post in threaded view
|

Re: how to search multiple patterns and move to end

张嘉琳
Use '\|' in regular expressions to match several patterns.

try
:g/a1\|b1/m$



2009/3/15 vimlover <[hidden email]>


Hello,
I have new for vim.
I have a file like

alter table a1 enable constraints xxx;

alter table b1 enable constraints xxx;

alter table c1 enable constraints xxx;
....(millions of rows...)

I know if I want to search pattern "a1", and, move the line (with this
pattern) to end of file by using
:g/a1/m$

but if if want to search a couple of patterns, for example,like a1 and b1,
and move to the end of files,
how can I do?


Thank you for help

Vimlover




--
View this message in context: http://www.nabble.com/how-to-search-multiple-patterns-and-move-to-end-tp22519796p22519796.html
Sent from the Vim - General mailing list archive at Nabble.com.





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

Reply | Threaded
Open this post in threaded view
|

RE: how to search multiple patterns and move to end

Gene Kwiecinski
In reply to this post by vimlover

>alter table a1 enable constraints xxx;
>alter table b1 enable constraints xxx;
>alter table c1 enable constraints xxx;
>I know if I want to search pattern "a1", and, move the line (with this
>pattern) to end of file by using
>:g/a1/m$
>but if if want to search a couple of patterns, for example,like a1 and
b1,
>and move to the end of files,
>how can I do?

Why not

        :g/[abc]1/m$

if you're guaranteed those patterns are unique to the lines you want to
get?

If you want discrete labels only, eg, "a1", "b3", "c5", etc., ie, those
that don't fit a particular regexp pattern, then

        :g/a1\|b3\|c5\|.../m$ ("..." meaning "etc.", not taken
literally)

will do it.


Quick example, if I have a bunch of webpages where I want to get rid of
the prepended paths to each image, .js file, etc., and they fit the
pattern

        wu1_files/imageX.jpg in file 'wu1.html'
        wu3_files/imageY.jpg in file 'wu2.html'

etc., I'll edit the whole clump of files in one shot, then do

        :argdo g/wu[0-9]_files\//s///g

to get rid of them and leave just

        imageX.jpg
        imageY.jpg

respectively.  Where those files wouldn't fit the 'wu\d' pattern, I
would have to do something like a generic

        :argdo g/[a-zA-Z0-9]*_files\//s///g

or more specific

        :argdo g/name1_files\/\|name2_files\//s///g

instead.

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

Reply | Threaded
Open this post in threaded view
|

RE: how to search multiple patterns and move to end

vimlover
Thank you all for reply.
Thanks again.


Gene Kwiecinski wrote
>alter table a1 enable constraints xxx;
>alter table b1 enable constraints xxx;
>alter table c1 enable constraints xxx;
>I know if I want to search pattern "a1", and, move the line (with this
>pattern) to end of file by using
>:g/a1/m$
>but if if want to search a couple of patterns, for example,like a1 and
b1,
>and move to the end of files,
>how can I do?

Why not

        :g/[abc]1/m$

if you're guaranteed those patterns are unique to the lines you want to
get?

If you want discrete labels only, eg, "a1", "b3", "c5", etc., ie, those
that don't fit a particular regexp pattern, then

        :g/a1\|b3\|c5\|.../m$ ("..." meaning "etc.", not taken
literally)

will do it.


Quick example, if I have a bunch of webpages where I want to get rid of
the prepended paths to each image, .js file, etc., and they fit the
pattern

        wu1_files/imageX.jpg in file 'wu1.html'
        wu3_files/imageY.jpg in file 'wu2.html'

etc., I'll edit the whole clump of files in one shot, then do

        :argdo g/wu[0-9]_files\//s///g

to get rid of them and leave just

        imageX.jpg
        imageY.jpg

respectively.  Where those files wouldn't fit the 'wu\d' pattern, I
would have to do something like a generic

        :argdo g/[a-zA-Z0-9]*_files\//s///g

or more specific

        :argdo g/name1_files\/\|name2_files\//s///g

instead.

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