Any Microsoft Word wizards interested in helping out with a little find/replace question?
February 9, 2012 11:26 AM   Subscribe

Any Microsoft Word wizards interested in helping out with a little find/replace question? I have a document with hundreds of lines of text that begin like this: "101 0 Music player..... 102 0 The interim... 103 0 Beneath the..." I need to keep the first group of digits but remove that 0, so that the result looks like this: "101 Music player..... 102 The interim... 103 Beneath the..." One added dimension: that second digit is not always a 0; sometimes it's another digit. Any thoughts? Thanks!
posted by kaboomer to Computers & Internet (16 answers total) 2 users marked this as a favorite
Other than looking for a more elegant solution, is there a reason why you can't just search for " 0 " and replace with " ", then replace " 1 " with " ", " 2 " with " " etc? That's 10 find and replaces - should take a minute or two at most.
posted by MUD at 11:30 AM on February 9, 2012

Have you tried doing a find for [space]0 (replace [space] with an actual space) and leaving the replace field blank?
posted by desjardins at 11:31 AM on February 9, 2012

Find [space]0[space] replace with [space]
posted by Heart_on_Sleeve at 11:32 AM on February 9, 2012

On re-reding the question, use the special character "any digit"... Probably ^# instead of space in your find
posted by Heart_on_Sleeve at 11:33 AM on February 9, 2012

I'd recommend the above, while being sure to select "Find whole words only" under the more options.
posted by BevosAngryGhost at 11:33 AM on February 9, 2012

You could try formatting into a table by selecting all of the text, then going to Table>Convert>Text to Table. You would separate your text at the spaces between your text strings.

This makes a super ugly, super long table that will go off the end of your page if you're not careful.

If you have Excel, you could try a copy and paste of the text into the first column of an Excel worksheet, and use the same function. Data>Text to Columns. Select Fixed Width as your original data type, and then create break lines where you need them.
posted by sillymama at 11:33 AM on February 9, 2012 [6 favorites]

Seconding text to columns in Excel. In a case where the data is this uniform, it's a lot more foolproof than a whole bunch of find->replace operations.
posted by griphus at 11:35 AM on February 9, 2012

MUD and Heart_on_Sleeve are right; you could also use a wildcard search, using "[0-9]" (no quotes) to represent the digit.

I don't have time to write out full instructions right now, but google "wildcard search" or check out this comment for more details if you're interested.
posted by trig at 11:37 AM on February 9, 2012

Replacing [space]0[space] with [space] will work. I've used that sort of replacement many times. Make a backup copy of your file before you unleash the replacements though, because if the file has tonnes of text, you could be missing some weird formatting somewhere.
posted by vidur at 11:38 AM on February 9, 2012

-> google "wildcard search word" ...
posted by trig at 11:38 AM on February 9, 2012

Is there a reason this has to be done in Word?

AWK is just made for this.

My AWK is always a little rusty, but I think the script would be:

awk 'FNR>0 print $1,$3,$4,$5' oldfilename.txt > newfilename.txt
posted by roofus at 12:03 PM on February 9, 2012

OK, a very cludgy solution. Change to Courrier New font (or any monospace font). Increase the hanging indent to push any second lines of each paragraph out of the way. Hold ALT while selecting the "0" column.
posted by Classic Diner at 12:46 PM on February 9, 2012

This is the site that I always go to for Word wildcard searching reference. It is a bit technical and sometimes tough to get right, but all the wildcard types are listed in a table with a few screenshots to boot.

Probably will take some practice first. Just have some patience with it.
posted by lampshade at 2:24 PM on February 9, 2012 [1 favorite]

If there isn't any formatting (bold, italics, etc.) to worry about, copy it into TextPad (PC-only, but there are Mac text editors that can do this as well) and turn on Block Select Mode (located under the Configure menu). That will allow you to select just the column of numbers you don't want and delete them. Then copy and paste back into Word.
posted by hootch at 4:09 PM on February 9, 2012

I second the suggestion of putting it into excel. You should get one row per row in the word doc.

Assuming that all rows are in a format of "###_#_TEXT..." (where _ is a space) it would be pretty easy to do with a formula:

Create a new column and enter: =LEFT(A1,3) & RIGHT(A1,LEN(A1)-6), where A1 is the cell with your data. Then copy the formula for all rows.

This code would give you the first 3 characters from the left and then concatenate (the "&" operator) with everything from the left minus the first 6 characters (the ###_#_ pattern).

If your first number is not always three characters long, then you would have to change the formula to something like:

=LEFT(A1,FIND(" ",A1))&RIGHT(A1,LEN(A1)-FIND(" ",A1)-2)

This code would give you the characters starting from the left until the first space and then give you all the characters from the right minus the first number, and the erroneous number.

If your pattern is more complicated, such as not always being one character between spaces, you could further extend the formula by including another find.

Good luck!
posted by Kolath at 8:14 PM on February 9, 2012

Are they always three digits at the head? If so, I think the simplest way to do this is to use wildcards with the Word search (which you can do by clicking on the More button in the Find/Replace box, then checking "Use wildcards"):

([0-9][0-9][0-9]) [0-9]

which will find any three-digit number sequence followed by a space and any single digit number.

Then replace it with


which is a backreference to the three-digit number you searched for (including the parentheses in the search terms is essential for this, but it doesn't affect the actual search results).
posted by camcgee at 9:15 PM on February 9, 2012

« Older MeFites, I want to plan an era...   |  Help me develop a board game t... Newer »
This thread is closed to new comments.