Path: utzoo!utgpu!watmath!att!dptg!rutgers!usc!apple!oliveb!mipos3!omepd!merlyn From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.unix.questions Subject: Re: sed question: lower-to-upper case Message-ID: <4776@omepd.UUCP> Date: 9 Aug 89 14:39:50 GMT References: <830003@mechp10.UUCP> Sender: news@omepd.UUCP Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Hillsboro, Oregon, USA Lines: 40 In-reply-to: klein@mechp10.UUCP (Greg Klein) In article <830003@mechp10.UUCP>, klein@mechp10 (Greg Klein) writes: | I would like to use sed to change certain (not all) words in a text file | from lower case to upper case. For example, the selected words to be | changed might be all words that contain one or more lower case z's in | them (like 'zebra'). Any ideas? Yeah, don't use sed. #ifdef small_flame why do so many people wanna use the wrong UN*X tool? Sigh. #endif small_flame First, I'd recommend using Perl, just cause it seems to do things like this pretty well. If you *insist* on using sed because of its Turing-machine-equivalent power, you will need to do something elaborate with the 'hold' space and the 'y' command. Good luck! (No, I'm not going to post a 50-line sed script to do it... sorry. :-) Another solution if you toss the idea of using Perl would be to create the appropriate patterns with lex, and put in a little bit of C. Something along the order of: %% [a-z]*z[a-z]* { chp = yytext; while(*chp) putchar(toupper(*chp++)); } .|\n { ECHO; } (WARNING: probably bad code there, this was just an UNTESTED example...) But, get Perl. Then you can say something like: perl -pe 's|\w*z\w*|($& =~ y/a-z/A-Z/),$&|eg;' and do what you want in *one* line. Just another Perl hacker, -- /== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\ | on contract to Intel, Hillsboro, Oregon, USA | | merlyn@iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn | \== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/