Change one word in all .rtf files in one folder?
Change one word in all .rtf files in one folder?
Hi, macro mavens & other super users,
Is there way for me to change one word in all NWP (.rtf) files in a certain folder? There are probably close to 200 files in this folder, and the last thing I'd want to do is manually open them all to change one word in each one (some don't even have the word, but I wouldn't know that until I opened them).
Thanks!
Eric
Is there way for me to change one word in all NWP (.rtf) files in a certain folder? There are probably close to 200 files in this folder, and the last thing I'd want to do is manually open them all to change one word in each one (some don't even have the word, but I wouldn't know that until I opened them).
Thanks!
Eric
Re: Change one word in all .rtf files in one folder?
Hi Eric,
Nisus doesn't have any way to search files without opening them AFAIK. You can use the Finder to search the documents, but it doesn't seem to be very reliable, i.e., it may not find all instances of the word your looking for.
The easiest way to do this using NWP is to just open all the files, and do a Find/Replace on All Open Files. Nisus has a nice display that will show which files have hits and how many, and allow you to jump to any. You can also just do a Find/Replace. When you're done, use <option> Close to close them all. With 200 files, this will give you quite a show, but it should work fine. (This will overwhelm/obliterate your "Open Recent" history )
To avoid any mishaps make sure to close all other files before you start this.
One could also write a macro that goes through the files one by one, but the net effect will really be the same. The macro too will have to open each file first to find the word (or not), and then close it again. I guess one thing the macro can do is to open the files without displaying them, unless there is a find hit.
Nisus doesn't have any way to search files without opening them AFAIK. You can use the Finder to search the documents, but it doesn't seem to be very reliable, i.e., it may not find all instances of the word your looking for.
The easiest way to do this using NWP is to just open all the files, and do a Find/Replace on All Open Files. Nisus has a nice display that will show which files have hits and how many, and allow you to jump to any. You can also just do a Find/Replace. When you're done, use <option> Close to close them all. With 200 files, this will give you quite a show, but it should work fine. (This will overwhelm/obliterate your "Open Recent" history )
To avoid any mishaps make sure to close all other files before you start this.
One could also write a macro that goes through the files one by one, but the net effect will really be the same. The macro too will have to open each file first to find the word (or not), and then close it again. I guess one thing the macro can do is to open the files without displaying them, unless there is a find hit.
philip
Re: Change one word in all .rtf files in one folder?
G'day, Eric et al
I would use BBEdit for this. No need to open any of the files. Very fast.
Cheers,
Adrian
I would use BBEdit for this. No need to open any of the files. Very fast.
Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
macOS Ventura
Nisus Writer user since 1996
Re: Change one word in all .rtf files in one folder?
Hi, Philip and Adrian,
I really appreciate your help on this. I have not yet had time to try either method, but I will need to do this sometime – soon I think.
I'm not sure how to do it with BBEdit, Adrian, but maybe it's simple if I read up on it. I do have BBEdit on my computer, but I don't recall what I used it for Maybe I used it to edit an InDesign script … ?
Thanks to both of you!
Eric
I really appreciate your help on this. I have not yet had time to try either method, but I will need to do this sometime – soon I think.
I'm not sure how to do it with BBEdit, Adrian, but maybe it's simple if I read up on it. I do have BBEdit on my computer, but I don't recall what I used it for Maybe I used it to edit an InDesign script … ?
Thanks to both of you!
Eric
Re: Change one word in all .rtf files in one folder?
G'day, Eric et al
BBEdit > Search > Multi-File Search…
A window similar to NWP's Find & Replace window is displayed.
In the "Search in" field there you can choose one or more folders. The Replace All operation will affect all files in the chosen folders.
Suppose you wished to change the domain name of a Website in which each page makes mention of its URL. You would set the chosen folder to the topmost folder (ie, the one that contains the entire Website), click on the "Options" button, and tick the "Search nested folders" checkbox.
Tip: Don't bother going to make yourself a cup of coffee while you're waiting for the task to be completed.
Cheers,
Adrian
BBEdit > Search > Multi-File Search…
A window similar to NWP's Find & Replace window is displayed.
In the "Search in" field there you can choose one or more folders. The Replace All operation will affect all files in the chosen folders.
Suppose you wished to change the domain name of a Website in which each page makes mention of its URL. You would set the chosen folder to the topmost folder (ie, the one that contains the entire Website), click on the "Options" button, and tick the "Search nested folders" checkbox.
Tip: Don't bother going to make yourself a cup of coffee while you're waiting for the task to be completed.
Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
macOS Ventura
Nisus Writer user since 1996
Re: Change one word in all .rtf files in one folder?
Thank you, Adrian. Flash!
Brad
Brad
Re: Change one word in all .rtf files in one folder?
Adrian,adryan wrote: ↑2024-10-23 00:32:34 G'day, Eric et al
BBEdit > Search > Multi-File Search…
A window similar to NWP's Find & Replace window is displayed.
In the "Search in" field there you can choose one or more folders. The Replace All operation will affect all files in the chosen folders.
Suppose you wished to change the domain name of a Website in which each page makes mention of its URL. You would set the chosen folder to the topmost folder (ie, the one that contains the entire Website), click on the "Options" button, and tick the "Search nested folders" checkbox.
Tip: Don't bother going to make yourself a cup of coffee while you're waiting for the task to be completed.
Cheers,
Adrian
I finally found the time to get this done with BBEdit. Thank you for teaching me how to do this. It worked great!
Eric
Re: Change one word in all .rtf files in one folder?
@adryan
Hello, Adrian (or anyone else who know the answer).
I replaced one word in many files with BBedit. Worked great.
Then I wanted to replace this
with this
(After the digits that is supposed to be an en dash followed by five spaces.)
When I did so, BBedit made the changes (and I accepted them). However, rather than an en dash it put in
So I'm wondering how to get BBedit to actually insert an en dash. If I find out, I think it'll be straightforward enough to replace all of the
instances in all of the files with the desired en dash.
Oh, I did search the internet for this, including a search of the v. 15 BBedit users manual. But I could not find anything.
Thank you for any help you can offer.
Hello, Adrian (or anyone else who know the answer).
I replaced one word in many files with BBedit. Worked great.
Then I wanted to replace this
Code: Select all
(gim. 1943)
Code: Select all
(1943– )
When I did so, BBedit made the changes (and I accepted them). However, rather than an en dash it put in
Code: Select all
–
Code: Select all
–
Oh, I did search the internet for this, including a search of the v. 15 BBedit users manual. But I could not find anything.
Thank you for any help you can offer.
Re: Change one word in all .rtf files in one folder?
G'day, Eric et al
When I tried replacing "(gim. 1943)" with "(1943– )", it worked fine. Of course, ticking the "Grep" checkbox will give a slightly different result, but the en dash still appears as it should.
A search of the Net found a similar discussion at:–
https://forums.livecode.com/viewtopic.php?t=18321
But I couldn't figure out how to do the conversion in BBEdit.
I suggest you contact BBEdit and ask them; I have found them quite helpful in the past. Alternatively, you can post a question on their BBEdit Talk forum. It'd be great if you could let us know here on the Nisus forum what the answer to your problem is.
Cheers,
Adrian
When I tried replacing "(gim. 1943)" with "(1943– )", it worked fine. Of course, ticking the "Grep" checkbox will give a slightly different result, but the en dash still appears as it should.
A search of the Net found a similar discussion at:–
https://forums.livecode.com/viewtopic.php?t=18321
But I couldn't figure out how to do the conversion in BBEdit.
I suggest you contact BBEdit and ask them; I have found them quite helpful in the past. Alternatively, you can post a question on their BBEdit Talk forum. It'd be great if you could let us know here on the Nisus forum what the answer to your problem is.
Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
macOS Ventura
Nisus Writer user since 1996
Re: Change one word in all .rtf files in one folder?
G'day, Eric et al
No, I meant using the Find/Replace mechanism within BBEdit. I had just copied fragments from your posting and pasted them into a new BBEdit document, then applied the substitution.
I've now gone back to using BBEdit's Multi-File Search on a Nisus RTF document. With the "Grep" checkbox unticked, no substitution is made. When the "Grep" checkbox is ticked, the en dash is encoded as "–", as you found. So there's something peculiar about the encoding of en dashes (and some other characters). Some people talk about a clash between UTF-8 and UTF-16.
Try as I might, I could not find a solution. I suggest you contact BBEdit.
Cheers,
Adrian
No, I meant using the Find/Replace mechanism within BBEdit. I had just copied fragments from your posting and pasted them into a new BBEdit document, then applied the substitution.
I've now gone back to using BBEdit's Multi-File Search on a Nisus RTF document. With the "Grep" checkbox unticked, no substitution is made. When the "Grep" checkbox is ticked, the en dash is encoded as "–", as you found. So there's something peculiar about the encoding of en dashes (and some other characters). Some people talk about a clash between UTF-8 and UTF-16.
Try as I might, I could not find a solution. I suggest you contact BBEdit.
Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
macOS Ventura
Nisus Writer user since 1996
Re: Change one word in all .rtf files in one folder?
G’day, Eric et al
I tried using a “sed” command in Terminal, but “‚Äì‚Äì” (that’s twice) was inserted (in a Nisus RTF document) instead of the desired en dash.
Then I created a document in TextEdit, saved it as RTF, then ran the Terminal command. This time “–” was inserted (in the TextEdit RTF document) instead of the desired en dash.
I suspect that, unless Nisus offers a multi-file Find & Replace feature for its own RTF files, doing such things with (at least some) non-alphanumeric characters may not be possible.
Cheers,
Adrian
I tried using a “sed” command in Terminal, but “‚Äì‚Äì” (that’s twice) was inserted (in a Nisus RTF document) instead of the desired en dash.
Then I created a document in TextEdit, saved it as RTF, then ran the Terminal command. This time “–” was inserted (in the TextEdit RTF document) instead of the desired en dash.
I suspect that, unless Nisus offers a multi-file Find & Replace feature for its own RTF files, doing such things with (at least some) non-alphanumeric characters may not be possible.
Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
macOS Ventura
Nisus Writer user since 1996
Re: Change one word in all .rtf files in one folder?
G'day, Eric et al
I think I’ve got it!
BBEdit Find field: gim\. 1943
BBEdit Replace field: 1943\\endash
(That’s with your five trailing spaces in the Replace expression.)
Have the "Grep" checkbox ticked. If you have the "Grep" checkbox unticked, you need to omit the backslash in the Find expression and one of the backslashes in the Replace expression.
There is, however, a caveat. If the insertion point is anywhere in the Find expression in a Nisus document, the string will not be found in that document.
Cheers,
Adrian
I think I’ve got it!
BBEdit Find field: gim\. 1943
BBEdit Replace field: 1943\\endash
(That’s with your five trailing spaces in the Replace expression.)
Have the "Grep" checkbox ticked. If you have the "Grep" checkbox unticked, you need to omit the backslash in the Find expression and one of the backslashes in the Replace expression.
There is, however, a caveat. If the insertion point is anywhere in the Find expression in a Nisus document, the string will not be found in that document.
Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
macOS Ventura
Nisus Writer user since 1996