From bjdouma@xs4all.nl Sun Apr 13 00:43:33 1997 Path: fu-berlin.de!newsfeed.nacamar.de!news-feed.inet.tele.dk!cpk-news-hub1.bbnplanet.com!news.bbnplanet.com!feed1.news.erols.com!newsfeeds.sol.net!hammer.uoregon.edu!news.oru.edu!news.iac.net!het.net!newsgate.cistron.nl!wirehub!xs4all!bjdouma From: bjdouma@xs4all.nl (Bauke Jan Douma) Newsgroups: comp.editors Subject: Re: joe: Upcasing Replacement after Search Date: 12 Apr 1997 18:01:14 GMT Organization: a training zoo Lines: 59 Distribution: inet Message-ID: <5ioila$f35$1@news0.xs4all.nl> References: <5im7g1$937$1@news0.xs4all.nl> Reply-To: bjdouma@xs4all.nl NNTP-Posting-Host: xs2.xs4all.nl X-XS4ALL-Date: Sat, 12 Apr 1997 20:01:14 MET DST In article <5im7g1$937$1@news0.xs4all.nl>, Bauke Jan Douma wrote: >In article , >Paul O Bartlett wrote: >> I use the joe editor, version 2.8, under SunOS 4.1.4. (I also have >>a port to DOS, although it is a little bit queasy.) joe can do search >>and replace somewhat like vi, but the two are broken into two tasks in >>reply to prompts. >> >> Suppose, to keep things easy, I have a large text file, and for >>reasons of my own I need to change the first word on every line to >>uppercase. We will assume for now that no such word contains any >>punctuation marks. The following regexp, in reply to the search >>prompt, will find the first word in a line: >> >>\^\+ \<\[A-Za-z]\*\> <---- in case there are leading blanks >> >>Prompt responses can tell joe to replace every matching occurrence in >>the file, and the replacement string may itself be a regexp. Like vi, >>joe does have \& to replace with whatever string was found by the >>match, but I have not found a way to convert the corresponding found >>string to uppercase and use that as the replacement string, along the >>lines of \U& in vi. >> >> Anybody got any experience or ideas on how to do this in joe? This >>is not just hypothetical: I have actually had to do this a couple of >>times on large files and had to use another editor to do it. (And >>please do not merely suggest that I change to vi or a clone. I do not >>need a sledgehammer to squash an ant.) > >I suppose you have 'tr', so my solution would be to use that, by defining >the following macro (in this example placed under Ctrl-F): > > --- MACRO: uppercase first word on each line --- >:def upfw ffirst,txt,"\\^\\+ \\<\\[A-Za-z]\\*\\>",rtn,rtn,rtn,markk,bol,markb,filt,"tr '[a-z]' '[A-Z]'",rtn,nextword >upfw ^F What you could also do is use sed and filter the file through the following script, either from the command-line or from within joe: #!/bin/sh # uppercase first word on each line of input-file cat $* | sed ' h s/\([ ]\{1,\}\).*/\1/ y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/ x s/[^ ]*[ ]*// H g s/\n//' BJ -- We forfeit three-fourths of ourselves to be like other people -- Schopenhauer