[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: funny...



Steve Reindl wrote:
> OK so I'm stupid. How do I get "hello world" out of this?

sed '/^[when][coders]/!d
    /^...[discover].$/d
   /^..[real].[code]$/!d
' /usr/share/dict/words

Or:
sed '/^[when][coders]/!d;/^...[discover].$/d;/^..[real].[code]$/!
d' /usr/share/dict/words


1. Start with the dictionary file (lots of words) (/usr/share/dict/words).
On Solaris, this file is in /usr/share/lib/dict/words.
2. Run a sed filter on it.
3. Out pops "hello world". :=)

To explain step 2, for the sed-impaired or the synaptically challenged:
1. Patterns are bounded by "/" characters, followed by a command.
2. The command is applied to the lines matching the pattern.
3. "//d" would mean "get rid of the matches"
4. "//!d" would mean "keep only the matches" (i.e. get rid of the non-matches).
5. /usr/share/dict/words is a file of words, one word per line.

Now the sed regexes, one by one:
A. /^[when][coders]/!d ==> keep words that start with "w", "h", "e", or "n",
and then followed by a "c", "o", "d", "e", "r", or an "s".

   $ sed '/^[when][coders]/!d' /usr/share/dict/words

[898 words total, "HEllo" and "WOrld" are among them.]

B. /^...[discover].$/d ==> get rid of five letter words with any letter in
the word "discover" as the fourth character of the word.

   $ sed '/^[when][coders]/!d;/^...[discover].$/d' /usr/share/dict/words

[840 words total, "helLo" and "worLd" are NOT among them.]

C. /^..[real].[code]$/!d ==> keep only five letter words with a r, e, a, or l
in the third character and c, o, d, or e as the last character.

[</drumroll> ... 2 words total, and "heLlO" and "woRlD" are they.]

QED.

Mike808/

---------------------------------------------
http://www.valuenet.net



-
To unsubscribe, send email to majordomo@silug.org with
"unsubscribe silug-discuss" in the body.