Wednesday, March 2, 2011

Re: search and replace with word list

On 03/02/2011 02:30 PM, Raleigh Rinehart wrote:
> Now what I would like to do is to replace each occurrence of MODULEX in
> file1 with the corresponding word in file 2.
>
> By corresponding I mean if the lines (from file 1) and the words (from file
> 2) were both well ordered sets then the match is determined by the index
> into the set, or in other words a one-to-one correspondence.

This is a bit confusing without a clearer picture of what files 1
& 2 contain, as well as the desired output given those files. If
I understand what you want, file1.txt looks something like

...
<Folder><![CDATA[C:\work\sources\foo\bar\baz\MODULEX\lib]]></Folder>
...
<Folder><![CDATA[C:\work\sources\foo\bar\baz\MODULEX\lib]]></Folder>
...

and you have file2.txt which looks something like

...
spatula
kumquat
...

and you'd like the output to look something like

...
<Folder><![CDATA[C:\work\sources\foo\bar\baz\spatula\lib]]></Folder>
...
<Folder><![CDATA[C:\work\sources\foo\bar\baz\kumquat\lib]]></Folder>
...


such that the first instance of MODULEX gets replaced with the
first item in file2.txt, the second instance of MODULEX gets
replaced with the second item from file2.txt, etc until you run
out of matches in either file1.txt or file2.txt

If you could reply with either "yes, that understanding is
correct" or "oh, here's a better, clearer example of before &
after" it would help in formulating a solution.

-tim


--
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

No comments: