From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Fri, 30 Oct 2009 13:35:32 +0000 From: Eris Discordia To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Message-ID: In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Subject: Re: [9fans] sed question (OT) Topicbox-Message-UUID: 94429e66-ead5-11e9-9d60-3106f5b1d025 Listing of file 'sedscr:' > s/^/ /; > s/$/aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ/; > s/ \([a-z]\)\(.*\1\)\(.\)/ \3\2\3/; > s/ \([a-z]\)\(.*\1\)\(.\)/ \3\2\3/; > s/.\{52\}$//; > s/ //; $ echo This is a test | sed -f sedscr This Is a test $ echo someone forgot to capitalize | sed -f sedscr Someone Forgot to capitalize This works with '/usr/bin/sed' from a FreeBSD 6.2-RELEASE installation. Above sed script stolen from: With a minor change: first three words to first two words. --On Thursday, October 29, 2009 15:41 +0000 Steve Simon wrote: > Sorry, not really the place for such questions but... > > I always struggle with sed, awk is easy but sed makes my head hurt. > > I am trying to capitalise the first tow words on each line (I could use > awk as well but I have to use sed so it seems churlish to start another > process). > > capitalising the first word on the line is easy enough: > > h > s/^(.).*/\1/ > y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/ > x > s/^.(.*)/\1/ > x > G > s/\n// > > Though there maye be a much easier/more elegant way to do this, > but for the 2nd word it gets much harder. > > What I really want is sam's ability to select a letter and operate on it > rather than everything being line based as sed seems to be. > > any neat solutions? (extra points awarded for use of the branch operator > :-) > > -Steve >