search/replace on multiple files?

  • Thread starter Ronald Florence
  • Start date
R

Ronald Florence

How do I do search/replace operations on multiple Word files, preferably
with both literal and regular expressions. As a simple example, how
would I replace "Zikhron" with "Zichron" in all the chapters of a ms.
I'm used to using grep, sed, awk, and/or perl for operations on multiple
files, but they only work with ascii files.

I'm using Word-2004. Thanks,
 
B

Bill Weylock

News is better than you would expect (based on reading your endnotes
thread). :) In fact, Word does a great job of this.

You do have to have all the documents open.

When you see the Replace dialog, click on the little blue arrow button to
the left of the entry fields. That will give you the rest of the utility
(which should be exposed as a default of course). Instead of the usual
Current Document All, select ³All Open Documents.²

Works well and fast for me, although my documents do you have your length.

You might want to check out a very inexpensive and gorgeously tended
shareware text editor called Tex-Edit Plus. It will do normal expression
searching.


Best,


- Bill


How do I do search/replace operations on multiple Word files, preferably
with both literal and regular expressions. As a simple example, how
would I replace "Zikhron" with "Zichron" in all the chapters of a ms.
I'm used to using grep, sed, awk, and/or perl for operations on multiple
files, but they only work with ascii files.

I'm using Word-2004. Thanks,




Panther 10.3.6
Office 2004
Windows XP Pro SP2
Office 2003
 
D

Daiya Mitchell

You do have to have all the documents open.
When you see the Replace dialog, click on the little blue arrow button to
the left of the entry fields. That will give you the rest of the utility
(which should be exposed as a default of course). Instead of the usual
Current Document All, select ³All Open Documents.²
How cool. I had no idea! Thanks, Bill. Always new discoveries to be made
in the F&R dialog.

Ron, I believe checking "use wildcards" gives Word's implementation of
regular expression searching (being able to search for things like "teach*"
and get teaching, teachers, etc, right? ) but...it might be a little broken
in MacWord. This article explains how it is supposed to work, re WinWord:
http://gmayor.com/replace_using_wildcards.htm
In Word 2001, it was definitely broken in certain ways--e.g., a wildcard
term would work with letters but not numbers. I thought I heard something
about improvements to wildcard searching in later versions, but am not sure
and have not tested. I believe that the Help topic on wildcards was accurate
about what Word 2001 could do, so that would be another place to
start--actually, there are several topics in Help, apparently. Don't recall
having seen recent discussions on this, but "wildcards" would be the proper
google keyword.

Daiya
 
R

Ronald Florence

Thanks to Bill & Daiya for the very useful comments and suggestions on
how to do search/replace operations on multiple files in Word. I was
getting ready to try a combination of applescript and shell programming
from the command line, but will gladly try the GUI approach.
 
P

Paul Berkowitz

Thanks to Bill & Daiya for the very useful comments and suggestions on
how to do search/replace operations on multiple files in Word. I was
getting ready to try a combination of applescript and shell programming
from the command line, but will gladly try the GUI approach.

I think Word wildcards should bee able to get what you want - it won't be
the same grep you know. It should work the same as in WinWord. And the Help
is not bad either : "Advanced search methods".

If you should be driven to AppleScript, it will be complicated. Be aware
that you can do grep and other Unix commands _within AppleScript via 'do
shell script' command. Also that it might be easier using the Satimage
scripting addition's superb regex features and commands:

http://www.satimage.fr/software/en/downloads_osaxen.html
http://www.satimage.fr/software/en/index.html

But Word wildcards can probably do it for you.

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
R

Ronald Florence

Paul said:
I think Word wildcards should bee able to get what you want - it won't be
the same grep you know. It should work the same as in WinWord. And the Help
is not bad either : "Advanced search methods".

I've never used WinWord, but from the Word Help, I think the regular
expressions available in Word should be fine.
If you should be driven to AppleScript, it will be complicated. Be aware
that you can do grep and other Unix commands _within AppleScript via 'do
shell script' command.

Actually I had been thinking of using the Applescript to tell Word to
replace "this" with "that" in a group of files. I don't think it will
be necessary. Opening all the files and doing a search/replace on "all
open files" from the Word GUI feels strange (I'm an old Unix CLI guy)
but seems to work fine.

Thanks for the suggestions,
 
J

John McGhie

Great pick-up, Bill :)

I wish to point out that "All open documents" is a brand-new Macintosh only
feature of Word :)

Others have referred you to the Wildcards find/replace. This is not "quite"
what a Unix pilot would describe as "regex" but it's close enough. You have
a maximum of nine levels of nesting within your expression, and I think it's
three pending operations within a statement.

I've never found I need any more. The problem with this sort of thing in
normal documents is that the variability of the content in the documents is
such that really hairy-chested regex find/replaces are simply not safe!
(Unless I wrote the documents, of course: then I know they will be totally
consistent... Not!)

Given the complexity of the syntax and the fact that I have to look it all
up every time I use it, I tend to record the syntax into a VBA Macro every
time I get it right. This is pretty simple: When you get one to work
correctly: turn on the macro recorder and then perform a Replace. It will
record the entire contents of the Find and Replace dialogs into the code for
you, so you have it stored for all time, and you can edit it as required.

Cheers

News is better than you would expect (based on reading your endnotes thread).
:) In fact, Word does a great job of this.

You do have to have all the documents open.

When you see the Replace dialog, click on the little blue arrow button to the
left of the entry fields. That will give you the rest of the utility (which
should be exposed as a default of course). Instead of the usual Current
Document All, select ³All Open Documents.²

Works well and fast for me, although my documents do you have your length.

You might want to check out a very inexpensive and gorgeously tended shareware
text editor called Tex-Edit Plus. It will do normal expression searching.


Best,


- Bill







Panther 10.3.6
Office 2004
Windows XP Pro SP2
Office 2003


--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Consultant Technical Writer
Sydney, Australia +61 4 1209 1410
 
M

montagnana

I just want to make sure that I'm understanding correctly. To do a
search of documents (looking for a text string or something like that)
you have to have all the documents open. I've switched over to Word
from WordPerfect, which had many problems, but you could do a search of
all the files in a folder without opening them. I have almost 50 files
that I need to search from time to time, and I don't really relish the
idea of having to open them all. Any suggestions?
Thank you.
David Sanders
 
B

Bill Weylock

Word 98 used to do that too. No idea why they thought we could not be
trusted with that much raw functionality in 2004. (I bought 2001 and never
even cracked it.)

You can use the Mac OS Find function to search closed documents if you give
the system time to index the folders you¹ll want to search.

Look in Help for Find Content.


Best,


- Bill


I just want to make sure that I'm understanding correctly. To do a
search of documents (looking for a text string or something like that)
you have to have all the documents open. I've switched over to Word
from WordPerfect, which had many problems, but you could do a search of
all the files in a folder without opening them. I have almost 50 files
that I need to search from time to time, and I don't really relish the
idea of having to open them all. Any suggestions?
Thank you.
David Sanders




Panther 10.3.6
Office 2004
Windows XP Pro SP2
Office 2003
 
M

montagnana

I tried that, but even after indexing the folders it doesn't always
find a text string that I know is there. Sometimes it shows files where
the text string doesn't exist. Maybe there are too many files to go
through (never a problem in WordPerfect).
If you have any other suggestions, I would be really grateful.
Thanks.
David
 
B

Bill Weylock

Sorry.

I¹ve never really tried to use the content find feature.

Maybe someone else has a software suggestion. You might try searching
VersionTracker or MacFixit for solutions.

By the way, I was astonished to find the feature missing in new versions of
Word. It had been there for many years. I at first assumed it had been
moved. Never occurred to me that they would remove it, and it still seems
like an extremely bad idea (EBI).


Best,


- Bill


I tried that, but even after indexing the folders it doesn't always
find a text string that I know is there. Sometimes it shows files where
the text string doesn't exist. Maybe there are too many files to go
through (never a problem in WordPerfect).
If you have any other suggestions, I would be really grateful.
Thanks.
David




Panther 10.3.6
Office 2004
Windows XP Pro SP2
Office 2003
 
J

John McGhie

The Mac OS Find function is very good, but you need to know that not
everything in a Word document is text. Some of it (particularly in headers,
footers, graphics etc...) is binary information that cannot be searched. In
WordPerfect, the content of the file was tagged ASCII. In Word, it's not
tagged, there are no codes embedded, and the text is compressed Unicode.

The OS Index tool is very good, but it helps to read the Mac Help Topic
"Indexing your files" and its subtopics, and has been mentioned, give it up
to an hour to index your drive the first time (basically, trigger "Index
Now" and let the system run for an hour or two).

Yes, to do Find/Replace in Word, the file must be open in Word. You can
make a macro in Word that will process an entire folder or multiple folders
of files if you wish. It will handle an unlimited number of files, but you
need to know a little VBA or AppleScript coding to get it to work. Get back
to us if you need such a macro.

Cheers


I tried that, but even after indexing the folders it doesn't always
find a text string that I know is there. Sometimes it shows files where
the text string doesn't exist. Maybe there are too many files to go
through (never a problem in WordPerfect).
If you have any other suggestions, I would be really grateful.
Thanks.
David

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Consultant Technical Writer
Sydney, Australia +61 4 1209 1410
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top