Reputation: 121
File looks like:
INSERT INTO x VALUES (48394, '9-10-2007', 19);
INSERT INTO x VALUES (99981, '3-5-2008', 45);
I would like to replace each line with:
INSERT INTO x VALUES (48394, STR_TO_DATE('9-10-2007', %d-%m-%y), 19);
INSERT INTO x VALUES (99981, STR_TO_DATE('3-5-2008', %d-%m-%y), 45);
I can't seem to find how to deal with changing string names to replace
:%s/<WHAT GOES HERE>/add in STR_TO_DATE(...)/
Upvotes: 0
Views: 69
Reputation: 59277
If your data is structured exactly like that with no other strings delimited by '
and the contents are always the date you want to convert, searching for simply '.*'
will work:
:%s/'.*'/STR_TO_DATE(&, %d-%m-%y)
To be more specific, i.e. if other strings appear on the same line:
:%s/'\d*-\d*-\d*'/STR_TO_DATE(&, %d-%m-%y)
Upvotes: 1
Reputation: 78
Here's an example of a solution:
:%s/\(INSERT INTO x VALUES (.*,\) '\(.*\)'\(.*\)/\1 STR_TO_DATE('\2', %d-%m-%y)\3/g
Upvotes: 1