Given a file with exactly two lines for each IP (for a defined set of IPs) as follows:
<router ip="a.b.c.d" id="">
<router ip="p.q.r.s" id="">
a.b.c.d,23
p.q.r.s,24
...
...
Need to fill the xml attribute 'id' with matching value.
Vim Recording to rescue:
1. Go to a.b.c.d
2. Record in register 'c'
qc
3. search for comma
/\<,\>
4. Go to next word.
w
5. Copy the text after comma (which is the value of id) to buffer 'x':
"xy$
6. Step back to comma
b
5. Copy the text before comma to buffer 'z':
"zy0
6. Search for z-buffer-contents in file.
/\
To copy z buffer contents:
Ctrl-R z
7. Search for next instance
n
8. copy the value of id from x register to id=""
/id="
3w
"xp
9. search for next instance. (original instance)
n
10. Next line.
j
11. beginning of line.
0
Apply to 1000 lines:
1000@c
Done.