Friday, May 25, 2018

Re: VIM Advanced text string search HELP

On Friday, May 25, 2018 at 10:21:52 AM UTC+2, Matt Truslove wrote:
> Good morning,
> I have a very important XML file which contains a lot of important metadata. Recently my old computer has become useless so i managed to backup all my data and export all my files.
>
> as part of the backup i exported the metadata via an XML feature. But not realising that the new location would be different for all the files once moved.
>
> the XML file has a tag for Location and i need this to change whilst retaining the file name.
>
> i was told VIM is perfect for this. so fired fired up my old linux box to give it a go but no avail.
>
> please see the below example
>
> <key>Location</key><string>file:///Volumes/OLDDRIVE/OTHERFOLDER/aaaaa/bbbbb/ccccc/ddddd/eeeee/20Berksonax.uue</string>
>
> i want to find and replace the text between the "file:///" and the last but one "/" (as the last slash will affect the XML </string>.) but retain the file name, extension and end tag </string>
>
> to end up with
>
>
> <key>Location</key><string>file:///NewVolume/NEW_SSD/NEWFOLDER2018/0Berksonax.uue</string>

Hello,

how about this substitution?

%s#\(<key>Location</key><string>file://\)/\(Volumes\)/\(OLDDRIVE\)/\(OTHERFOLDER\)/.*/\(.*\)\(</string>\)#\1/NewVolume/NEW_SSD/NEWFOLDER2018/\5\6#

First try on one line (without the '%') to see if the result is precisely what you need.

Tom

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment