[OS X TeX] grep

Robert Bruner rrb at math.wayne.edu
Mon May 11 15:49:14 CEST 2009


Luis Sequeira read my mind when he wrote:

> > To Herb, and all the other great wizards,
> >
> > The search of TeXShop contains the grep option. Unfortunately, this is
> > inaccessible to all but a few, who learn grep and can remember it.
> >
> > Question: would it be possible to make it available to us, average
> > users? An English like scripting language, or a pull down type menu
> > structure? There was a word processor a while ago that had that.
> >
> > Like:
> >
> > Search for Char: not \, Char: ]
> >
> > meaning any char but \, followed by ].
> >
> > GG
> 
> I am certainly not one of the great wizards :-)
> but I believe that such an effort would be much harder than the effort  
> required to look up a few basic rules for grep. I, for one, looked up  
> how to do your example and it took me maybe one minute. Here is the  
> required regular expression:
> 
>      [^,]\]

I too do not recall how to write all the matches I need: I just look them
up as required.  It is quick, esp. after a few times.  I found the
O'Reilly book on vi had the admirable side-effect of teaching these
sorts of matches.  There are surely many other good sources too.
 
> In doing so, I made use of a little free application named Bwana,  
> which allows one to read man pages without using the Terminal. Just  
> type man:egrep (or man:ls, or whatever) in Safari's url box, and there  
> you have it.
> 
> The rules for regular expressions are not that hard. Most characters  
> just match themselves. Special characters, like brackets, backslash,  
> asterisk, can be "escaped" by preceding them with a backslash - hence  
> the \] above matches a single closing bracket. A string of characters  
> inside a pair of brackets matches any one of those characters - e.g.,  
> [abc] matches any of the letters a, b or c - unless the first  
> character inside is a caret - ^ - which means negation. Hence [^,]  
> matches any character except the comma.
> 
> There is much more, of course, but I hope this gives people an idea  
> that is not that hard.
> I don't always remember how to do it (I didn't remember about the  
> caret in the example above, for instance), but if necessary I look it  
> up. It has helped me countless times.

Bob Bruner




More information about the macostex-archives mailing list