up vote 3 down vote favorite
1
share [g+] share [fb]

Grep in Microsoft Word?

I'd like to pull all lines with a given string from a word document. In unix world... grep does this without a glitch. Windows is less than obvious for me.

link|improve this question
Belongs on Superuser.com – djhowell Nov 13 '09 at 18:55
feedback

migrated from serverfault.com Nov 13 '09 at 23:41

This question came from our site for system administrators and desktop support professionals.

4 Answers

With Cygwin (or access to a Linux machine) you could

antiword file.doc | grep "my phrase"

or

catdoc file.doc | grep "my phrase"

There are lots of command-line file format converters out there to grep in a similar fashion.

Purely in-Word solution could be to Ctrl+F (Find), and then Find All - however, I'm not sure if all versions of MS Word have Find All button.

link|improve this answer
2  
When I saw the question title I thought "Ha! That'd be nice, wouldn't it". Never again should I underestimate GNU programmers. – Phoshi Nov 14 '09 at 0:08
feedback

I know this sounds primitive, but what's stopping you from saving the file as .txt and then ripping it apart to your liking.

link|improve this answer
feedback

What does "line" mean in a Word context? The displayed line, which changes if you do anything to the page formatting? The paragraph? Something else?

You can do a bunch of stuff with Word's find-and-replace functions, including changing the formatting and other non-obvious things, but all of them will only act on the find-what text itself, not on any surrounding text.

link|improve this answer
grep's got that regex lovin', though! – Phoshi Nov 14 '09 at 0:13
feedback

PowerGREP will do exactly that for you, and fast - but not free. It's worth every penny, though, in my opinion. Plus, there is a 30-day free trial.

Screenshot of PowerGREP searching through a Word file

link|improve this answer
feedback

Your Answer

 
or
required, but never shown