VIM Advanced text string search HELP

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

VIM Advanced text string search HELP

Matt Truslove
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>

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: VIM Advanced text string search HELP

Keith Edmunds
If it were me, I'd put symlinks on the system to match the old path so
that the file doesn't need editing.

I'd also review my backup AND TEST RESTORE process.

--
"The best argument against democracy is a five-minute conversation with
the average voter" - Winston Churchill
   

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: VIM Advanced text string search HELP

Shlomi Fish-2
In reply to this post by Matt Truslove
Hi Matt,

On Fri, 25 May 2018 01:16:54 -0700 (PDT)
Matt Truslove <[hidden email]> 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.
>

see http://perl-begin.org/uses/text-parsing/ and
http://perl-begin.org/uses/xml/ and equivalents for other languages. See
https://blog.codinghorror.com/parsing-html-the-cthulhu-way/ .


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



--
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
http://youtu.be/xZLwtc9x4yA - Anime in Real Life!! (Parody)

What's the point of claiming your code is illegal?
I might anger a few, but I just wanna sue
    — http://www.shlomifish.org/humour/bits/Can-I-SCO-Now/

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: VIM Advanced text string search HELP

Matt Truslove
In reply to this post by Matt Truslove
Thank you for the resources, but all i have at the moment is a linux terminal and my work machine, so resources and software is limited

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: VIM Advanced text string search HELP

John Little-4
In reply to this post by Matt Truslove
It may help if you can start vim in non-compatible mode, such as with

    vi -N

I suggest also turning on search highlighting:

    :set hlsearch

If the path you want to replace does not have any dots, I would first search for the text that needs to be replaced, perhaps

/\/\/\/[^.]\+\/

With search highlighting, you can see what's been matched.  When you're happy with it,

    :%s##///new/path/to/file/

(Note the # above is an arbitrary choice, usually one uses / but that's messy here.)

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: VIM Advanced text string search HELP

7tommm
In reply to this post by Matt Truslove
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: VIM Advanced text string search HELP

Matt Truslove
In reply to this post by Matt Truslove
Great, i will run some tests now. thanks for your help, i will report back

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: VIM Advanced text string search HELP

Matt Truslove
In reply to this post by Matt Truslove
Thank you for all your help, TOM M had the solution

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.