sqlregexvimvi

vim group and substitute


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;

Solution

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