substitution in VI editor

Hi,
I have entries in a log file :

/tmp/nightly_releases/releases_20090315file1.zip
/tmp/nightly_releases/releases_20090315file2.zip

I want a "/" to be inserted in between directory and the file to complete the path like :

/tmp/nightly_releases/releases_20090315/file1.zip
/tmp/nightly_releases/releases_20090315/file2.zip

Any script or command for it that i can run from console (not in command promt in VI editor ) please help. Thanks in advance.

try:

perl -pi -e 's#(releases\_\d+)(file)#\1/\2#' logfile

Thread subject:

Which one should it be? To do it in VI(m) (as your subject suggests) it would be

:%s/\(file.\.zip$\)/\/\1/

To do it without VI(m) (as the body of your message suggests), use Yogesh' suggestion, with 2 corrections:

  • There's usually no need to escape an underscore
  • Backrefs (\1, \2) are better written as $1, $2