Upcoming Events

Cloud Connect
Santa Clara
Feb 13-16, 2012

Cloud Connect brings together the entire cloud eco-system to better understand the transformation we're experiencing and promises to be the defining event of the cloud computing industry. Learn about the latest cloud technologies and platforms from thought leaders in Cloud Connect’s comprehensive conference.

Register Now!

More Events »

Subscribe to Newsletter

  • Keep up with all of the latest news and analysis on the fast-moving IT industry with Network Computing newsletters.
Sign Up


UnixWorld Online: Tutorial: Article No. 009: Part 4: Answers

Answers to Exercises

Solution to k37 Problem


% substitute /\(.*\)k37\(.*k37\)/\1q53\2

will do it. When there are two or more wild cards in a search pattern, the editor finds the longest match for the first one that allows any match for the subsequent ones, and so on.

























































Solution to Capitalization Problem


237 , 289 substitute :[^ ]*:\L\u&:g

Since the ``\u'' and ``\l'' metacharacters have limited reach, they don't end the effect of a ``\L'' or ``\U'' metacharacter--they only make a one-character exception.

Author's Note: Since I wrote this solution, I have lear ned that it will not work under many implementations of the editor. So, I've added below an alternate solution, more complex but more powerful, that should work everywhere.


237 , 289 substitute :\([A-Za-z]\)\([A-Za-z-]*\):\u\1\L\2:g

Even in editing environments where my first solution would work, the second one has certain advantages:

  • The second solution is not fooled by situations where a punctuation mark leads off a word.
  • It's up to you whether the second solution does or does not capitalize any but the first word in hyphenated compounds such as Frankfurt-am-Main. If you want to capitalize those subsequent words, just remove the last of the three hyphens within the second character class in my alternate solution.
























































Answer to No-Op Problem

The editor thinks a substitution has been successfully made whenever the outgoing search patter n is matched and no error condition is encountered, even if it is only replacing nothing with nothing. So when the editor finishes up by reporting the number of substitutions it has made, it is giving me a count of the empty lines in my file, which tells me how many paragraphs plus headlines plus list items I have. Then I divide this number into the count of lines in the file, to see whether my paragraphs have gotten too long.


















































Solution to HTML tags problem

Where the substitution command to add a tag at the start of a paragraph presently removes and then replaces any first character on the line, now it should remove and replace anything except a ``<'' character in that position. If that first character is a ``<'' it is necessary that the substitution command fail so it will change nothing. To arrange this, replace that period in the search pattern with a negative character class--``[^<]''-- which ma tches any character except the one that begins every HTML tag.

Similarly, replace the period in the other substitution pattern with the negative character class that matches any character except the one that always ends an HTML tag. Now the two commands will look like this:


global /^$/ + substitute /^[^<]/<P>&/
global /^$/ - substitute :[^>]$:&</P>:



















































Print This Page


e-mail Send as e-mail

Research and Reports

Hypervisor Derby
August 2011

Network Computing: August 2011

TechWeb Careers