Fix filenames with blank spaces...

79 views
Skip to first unread message

David Puente

unread,
Jul 8, 2023, 10:03:03 AM7/8/23
to BBEdit Talk
Hi folks, 
I need to find some trick to rename the text:

    <resource type="webcontent" identifier="g989516e6a95da788733f48e98192a620" href="web_resources/Anotación 2019-07-08 151143.png">

I need find all the .png names removing spaces and accents... Is there any pattern to make it possible? Thanks!!!!

Neil Faiman

unread,
Jul 8, 2023, 11:21:18 AM7/8/23
to BBEdit Talk Mailing List
It will be much easier for people to help you if you can tell us not just what your input looks like, but what you want it to look like after it has been transformed. Otherwise, we are just guessing, and are likely to give you a solution that doesn’t solve your problem.

Regards,
Neil Faiman

Roland Küffner

unread,
Jul 9, 2023, 4:52:55 PM7/9/23
to bbe...@googlegroups.com
You might have a hard time figuring out a pattern for this (as I guess that the amount of white space in the file names might differ and the file names may not follow a strict structure). You could write a script for the task. Or – if it was a one-shot-task – I would do the following steps:

1. Search for: href="(.+?)"     replace with   \1    (using Grep): choose "Extract" – this gives you a new file with all href-Strings in it
2. In the new file: Copy all text
3. Replace all whitespace with _ (an underscore)
3. (for Accents and other stuff add additionals search-replace steps here)
4. Add a tab to each line (you could use the "Prefix/Suffix" command in the "Text" menu for that
5. Mark the column left of the tab ("column zeor") with a rectangular selection (check the manual if you don't know how to do this)
6. Paste the copied text

Now you have a file with the structure
<old file name with spaces><tab><old_file_name_without_spaces>
Save this file and use it as a ad-hoc batch-search-replace source on your orignal file: To do this, choose "Text" > "Canonize …". with your generated file as a source.

That might just take a few minutes and may be an alternative for getting a script right – if you have a lot of different files to process, a script solution may be the wiser choice.

Roland



--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/6a83df15-0871-402a-8e0a-ce2995da0f3en%40googlegroups.com.

Darren Duncan

unread,
Jul 9, 2023, 8:53:31 PM7/9/23
to bbe...@googlegroups.com
In my experience, by far the easiest and simplest solution for this arises when
you just try to find and replace a single instance of a space in urls at a time.

Something like this search/replace pair (I didn't test it):

(\bhref="[^" ]*) ([^"]*\.png")

\1_\2

That example is just for spaces, not accents, and replaces the first occurrence
of a literal space in the url with an underscore.

You can run that with a replace-all op for the first space in each url, and then
hit replace-all again for each additional space, until it says there aren't any,
so eg if urls have no more than 3 spaces each then its 3 replace-all.

This works as long as your search/replace is idempotent, you are replacing with
something different than what you're replacing.

As for accents, you can deal with those with a similar process.

-- Darren

David Puente

unread,
Jul 9, 2023, 8:53:31 PM7/9/23
to bbe...@googlegroups.com
I tried to explain:
The text now is "Anotación 2019-07-08 151143.png” and I want to remove special characters (latin characters as accents) in all the png files texts… Consider there are spaces and it’s not needed to remove. Only change the accents to non accented words

Is it clear?

------ Mensaje original ------
De "Neil Faiman" <neil....@faiman.org>
Para "BBEdit Talk Mailing List" <bbe...@googlegroups.com>
Fecha 8/7/23, 17:21:00
Asunto Re: Fix filenames with blank spaces...

--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages