On Saturday, February 7, 2015 at 12:25:23 AM UTC+8, David Fishburn wrote:
> Assuming I have a list of names:
>
>
> John.Smith John.Smith
> Joe.Blow Joe.blow
> Sarah.Smith sarah.smith
>
>
> So in the above list, I need to find Joe.Blow and Sarah.Smith, since the case (and or spelling) is different on the 2nd part of the line.
>
>
>
>
> I couldn't come up with a way (assuming %s or Match or something) that would allow me to:
>
>
> 1. For each line
> 2. Grab the first text (^\S\+)
> 3. Check the rest of the line to find a match (or better yet NOT match) using CaSe
>
>
> I tried something like:
> %s/^\(\S\+\)\s\+\=eval(submatch(1))
>
>
> But I believe you can only use submatch() in the replacement part of the :substitute
>
>
> Perhaps a :g might do it.
>
>
> Vim 7.4.1-622
>
>
> Any suggestions?
>
>
> TIA,
> David
Well, if you can be sure the first parts of the lines are always case right and you want to make the trailing parts likewise too, it's not necessary to distinguish the lines, just replace them all whatsoever, it's simpler:
:%s/\c\(\S\+\)\s\+\zs\1/\1/
And as I happened to come across a certain portion of the "pattern.txt" help file when I wrote my last post here, I noticed the following line(:help \&):
"It matches the last concat, but only if all the preceding concats also match at the same position."
So I guess it('\&') can be used in your case too, the pattern could be:
/\c\(\S\+\)\s\+\zs\1\&.*
it matches the trailing parts in your file lines.
--
--
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.
Sunday, February 8, 2015
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment