Discussion on:

28
Comments

Join the conversation!

Follow via:
RSS
Email Alert
This has to be one of the most helpful tidbits of knowledge I've found on TechRepublic so far!

I work with an enterprise tape backup software that originated in Unix and was ported to Windows (poorly, I might add). The company that bought out this software ( EMC) didn't do much to update it and, hence, all the administration has to be done via the command line. Well, all the reports that you get from the command line are text based and, not surprisingly, the format is delimited by a random number of spaces!

I tried this method out on one of my reports and voila!, it worked perfectly! No longer do I have to bend over backwards to make my data readable and usable! Thank you Susan Harkins, you are an IT Goddess!
0 Votes
+ -
Contributr
Thank you
ssharkins@... 18th May 2009
Thank you for letting me know you found this tip helpful. I'm so glad, because it sounds like you've got quite a task with those reports!
You might want to look into a text editor that supports regular expressions.

To overcome the limitation of replacing any space sequence you can use other characters. For example ^ indicates beginning of line. So:

Find : ^[\s]{2,2}
Replace with : \t

Says look for and replace any two spaces in the beginning of the line with one tab.

The following:
Find : ^[\s]{4,4}([\S])
Replace with : \t\t\1

Says to look for and replace any four spaces between the start of line and any non-space character with two tabs.

These expressions can become as complex as you require them for your reports and then just saved and rerun on every report.
0 Votes
+ -
Contributr
Thanks!
ssharkins@... 19th May 2009
This is a great lesson -- thank you for sharing this information!
I can't get this or Susan's suggestion to work with Office 2003.
Does it work only in Office 2007?
0 Votes
+ -
Did you check the "Use wildcards" option on the expanded ("More") screen? It didn't work for me until I did.
0 Votes
+ -
Thanks dperley
rvanderhoof 20th May 2009
Thanks dperley. That worked for Susan's suggestion.
But I get a warning " ^ is not a valid special character" if I try Saurondor's suggestion in Word 2003.
0 Votes
+ -
that Saurondor refers to were refined in Unix for its many utilities that use pattern matching. They have been since been applied for use by Perl and other programs and are extremely flexible and powerful.
Microsoft products did not implement "regular expressions" as I know them. There are some similarities but for the most part IMHO, MS is in its own world regarding pattern matching. While useful, theirs pale when compared to "regular expressions".
0 Votes
+ -
Start of line
Saurondor 22nd May 2009
Apparently Word doesn't have a way to detect the start of line with their regular expression syntax. If what you're working with is a text document you might want to download and install PSPad or similar tool. Otherwise for word documents Open Office supports a better range of regular expressions and can open .doc files.
0 Votes
+ -
Moderator
Start of line in MS Office
NickNielsen Updated - 24th May 2009
Microsoft uses ^p for the paragraph marker and ^l for line breaks. One of these may work to search from the beginning of a line.
Yep, regexes are extremely useful. I myself have used vim for many years, but vim does have a challenging learning curve because it is based on the ancient vi editor. For those who've never learned vi wikipedia lists a number of editors worth considering:

http://en.wikipedia.org/wiki/Source_code_editor

One of the best known open-source editors around is
http://notepad-plus.sourceforge.net/uk/site.htm
(I've not used it, since I can do everything I need with a combination of vim and Perl, but it does have an excellent reputation).

This is just one of several tricks for cleaning up those pesky reports. In the expression {2,}you can add a second figure after the comma to specify how many spaces to replace with the tab character. E.G., {3,7} will replace any string of 3 through 7 of the specified characters with the designated character. In the example above, you would replace the space character with a tab for every string of 3-7 spaces.

Take a good look at drop-down menu at the bottom centre marked "Special." The items here can greatly increase your search and replace functionality. One example: you can switch from a listing of "Doe, John" to "John Doe" using the 'expression' search function.

To get started, open Word, and in the Help menu, search for "wild cards" then In the resulting list, look at "Advanced Search Methods" and in the text, click on the "Wildcard characters you can use when searching." (Wording on the Mac - may vary slightly on the PC.)

Have fun.
0 Votes
+ -
"This replace trick will work in any Office application, not just Word." ... Ctrl+H in Outlook?
0 Votes
+ -
Contributr
As far as I know, it works in all of the Office applicatins.
0 Votes
+ -
Actually, in Outlook 2K ...
Marshwiggle Updated - 9th Sep 2009
... not only does Ctrl+H not bring up the Find/Replace dialog, Replace isn't even on the Edit menu.

But the main thing is, this is going to save me a lot of work in Word, which I use to convert text-doc song sheets, where guitar chords have been placed over lyrics using spaces, to Word docs, where using tabs produces more accurate results. Thanks.
This doesn't work for me in either version of Word, I get a message saying invalid pattern search.

Are there any other settings that need to be adjusted as this would be a helpful tool.
0 Votes
+ -
Contributr
Did you check the Use Wildcards option, as instructed?
0 Votes
+ -
Yes I did
jim.beattie@... 24th May 2009
Yes I checked the wildcard option. In fact I did it both ways I tried all sorts of other combinations and characters. Without wildcards checked it searches the document and finds nothing.

0 Votes
+ -
Contributr
spaces
ssharkins@... 25th May 2009
Are you absolutely certain that you have multple spaces in this particular document?
0 Votes
+ -
Yes, I typed them in myself. This is the message I get:
"The Find What text contains a Pattern Match expression which is not valid"
0 Votes
+ -
Forget the space?
DuhGreek 27th May 2009
Are you certain that you entered a single space before the brace notation? The brace notation applies to the character/pattern that immediately precedes it. If there is nothing before it, you will get the error you mentioned.
You are correct, thanks for the tip, it works well. Guess I should have read the original script a little closer
0 Votes
+ -
Contributr
Great!
ssharkins@... 28th May 2009
I'm so glad you figured this out and thanks to everyone who helped!
0 Votes
+ -
LOL
Jacky Howe 24th May 2009
I've been manipulating text in notepad for years but I have never used this principal. I have always used the keyboard to make a space or tab and then copy it into the fields depending on what was being replaced. You learn something new every day. Thanks Susan. wink
0 Votes
+ -
This is why I like browsing through TechRepublic.

There is great information in both the articles and in the comments that follow.

So thank you Susan and 'comment contributors'.

And thank you TechRepublic.

0 Votes
+ -
Contributr
Thanks!
ssharkins@... 10th Jun 2009
Thank you -- I'm glad you found this one useful. I use it all the time!
Is it just me or is there an Excel dialog box embedded on this post between steps 5 and 6?

Otherwise, thanks for a higher-tech way to do what I have done before which is to search and replace on multiple spaces. You can also just search on " " (without the quotes).
0 Votes
+ -
Contributr
It's fixed
ssharkins@... 26th Jun 2009
I really don't know what happened. I suppose it was the wrong figure all along, but I really don't think so -- some figures don't really matter, but this one does, and I think if it had been the wrong figure, someone would've complained. But, I admit, it's possible I could've made that mistake. At any rate, it's the right figure now, so thanks for letting me know!
Keyboard Shortcuts:
Prev
Next
Toggle
Join the conversation
Formatting +
BB Codes - Note: HTML is not supported in forums
  • [b] Bold [/b]
  • [i] Italic [/i]
  • [u] Underline [/u]
  • [s] Strikethrough [/s]
  • [q] "Quote" [/q]
  • [ol][*] 1. Ordered List [/ol]
  • [ul][*] · Unordered List [/ul]
  • [pre] Preformat [/pre]
  • [quote] "Blockquote" [/quote]

Join the TechRepublic Community and join the conversation! Signing-up is free and quick, Do it now, we want to hear your opinion.