[ALUG] Regex

Brett Parker iDunno at sommitrealweird.co.uk
Sun Nov 11 11:35:21 GMT 2007


On Sun, Nov 11, 2007 at 10:54:47AM +0000, Brett Parker wrote:
> On Sun, Nov 11, 2007 at 09:56:25AM +0000, Ruth Bygrave wrote:
> > In a more-stupid-than-normal moment I ended up with a Text Edit  
> > document on my Mac with lots of capital I's in the middle of words. I  
> > tried 'check spelling' to see if it did an entire run of spell- 
> > checking through the document, but there was no dialog box.
> > Tried to go through it in NeoOffice, which I'm not that familiar  
> > with, but NeoOffice bombed.
> > Can somebody less brain-dead than I appear to be today come up with a  
> > bash script to pour the text into that does 'replace I not on word  
> > boundary with i'? (The infuriating thing is, I used to *know* this  
> > stuff, or at least where to look it up, but because I've been  
> > Abjuring Hackish Unixy Things since I was in mental hospital this  
> > summer, I don't even know where to start...)
> > Also 'replace 'fI ind' with 'I find', because the reason I was  
> > messing about with I's in the first place was there's a timing error  
> > with my Alphasmart Neo keyboard and it has a tendency to transpose  
> > letters.
> 
> Hmmm, wellllll, the first could probably be done with:
> 	sed -i.backup -s -e 's/\b\([^I]+\)I\([^I]+\)\b/\1i\2/;' filename
> 
> (That will *only* pick up capital I with one or more letters both sides
> of it)
> 
> The second is more tricky, assuming that "fI ind" isn't the only
> replacement that's required it makes it quite a lot harder, I'll have to
> ponder that one over breakfast.

OK - for the second part, assuming that it's just things ending I,
something like:
	sed -i.backup2 -s -e 's/\b\([a-zA-Z]\)I /I \1/;'

should do the trick.

-- 
Brett Parker



More information about the main mailing list