I have a csv file that contains 3 sets of ids. I want to use Vim to substitute the appropriate id into the appropriate places, e.g.
A | B | C |
1| 1 | 2 | 3 |
2|33 |11 | 31|
How i can to replace rows from csv like this in this exact order:
update table set id1 = 2, id2 = 3 where id3 = 1;
update table set id1 = 11, id2 = 31 where id3 = 33;
Assuming your CSV contains fields separated by comma and lines separated by newline you could use the following substitution command:
:%s/\(\d\+\),\(\d\+\),\(\d\+\)/update table set id1 = \2, id2 = \3 where id3 = \1;
:%s
a substitution acting on all lines of the file\d\+
match one or more digits\(\)
keep the match in a capture group\1
,\2
,\3
insert the first/second/third capture group