I have 100K rows file and every row contain date 12/13/2019. I want to replace that date with 12/20/2019. But when I am entering the command like :%s/12/13/2019/12/20/2019/g. It gives an error that couldn't find pattern. Format for date is (MM/DD/YYYY)
Asked
Active
Viewed 50 times
0
-
2StackOverflow is dedicated to helping solve programming code problems. Your Q **may be** more appropriate for [su] or [vim.se] , but read their help section regarding on-topic questions . AND please read [Help On-topic](https://stackoverflow.com/Help/On-topic) and [Help How-to-ask](https://stackoverflow.com/Help/How-to-ask) before posting more Qs here. Good luck. – shellter Oct 03 '20 at 15:05
-
use backslashes and be careful of course on your REGEXP . – francois P Oct 03 '20 at 15:06
-
Does this answer your question? [How to include forward slash in vi search & replace](https://stackoverflow.com/questions/11823616/how-to-include-forward-slash-in-vi-search-replace) – phd Oct 03 '20 at 15:32
-
https://stackoverflow.com/search?q=%5Bvim%5D+search+slash – phd Oct 03 '20 at 15:32
-
@phd I'm not sure that's a full duplicate. This question includes a `solaris` tag, and the behavior of current versions of `vim` and/or `vi` may not be applicable to the `vi` likely found on older Solaris releases. – Andrew Henle Oct 04 '20 at 15:40
-
@AndrewHenle I'm sure it's a full dup. Escaping slash with a backslash or using a different search character works in any `vi` clone in any OS. – phd Oct 17 '20 at 12:00
1 Answers
1
A substitution is made of several parts:
:<range>s/<search>/<replace>/<flags>
Between those parts, you have /
as default separator. Since /
separates the <search>
part from the <replace>
part, any /
in your search pattern is going to be interpreted as a separator, leading to undesirable results.
One solution is to escape your slashes with an anti-slash:
:%s/12\/13\/2019/12\/20\/2019/g
Another one (my favourite) is to use an alternative separator:
:%s@12/13/2019@12/20/2019@g
Reference:
:help :s
:help pattern-delimiter

romainl
- 186,200
- 21
- 280
- 313