Up-to-date articles will return when migration completes. Meanwhile viewing an old database.

WP C – Temp

RegEx One Atom Twelve

The use of the following command line syntax (sans quotes) is interchangeable:

  • โ€œegrepโ€
  • execution of grep with command line option [ -E ], โ€œgrep -Eโ€

Grep (and Grep for Windows)

Depending upon the nature of the search I want to perform, I often use grep, a GNU Operating System application, common to the Linux operating system. grep is available for Windows, so I use it there when I can for its unique ability to scan file contents. Not only does grep provide a means of locating a desired string of text from a collection of files on the filesystem, it is also an exercise in the use of regular expressions, and Command Line syntax.

When executing grep, one has the option to use basic, extended, or Perl compatible Regular Expressions. As there are several options for executing a search, I often reference the --help option on the command line, or the included HTML help files. The following excerpt from section 5.5 of the Grep [for Windows] HTML help manual explains the difference between the default grep behaviour (basic regex), and that of egrepโ€ 

egrep | grep -E: grep manual section 5.5

In basic regular expressions the metacharacters `?โ€™, `+โ€™, `{โ€˜, `|โ€™, `(โ€˜, and `)โ€™ lose their special meaning;
instead use the backslashed versions `\?โ€™, `\+โ€™, `\{โ€˜, `\|โ€™, `\(โ€˜, and `\)โ€™.

Traditional egrep did not support the `{โ€˜ metacharacter, and some egrep implementations support `\{โ€˜ instead, so portable scripts [ where portable is used in context to reference โ€œthat which may be used on any of the variety of diverse computer systemsโ€ ] should avoid `{โ€˜ in `egrepโ€™ patterns and should use `[{]โ€™ to match a literal `{โ€˜.

GNU egrep attempts to support traditional usage by assuming that `{โ€˜ is not special if it would be the start of an invalid interval specification. For example, the shell command `egrep โ€˜{1โ€ searches for the two-character string `{1โ€™ instead of reporting a syntax error in the regular expression. POSIX.2 allows this behavior as an extension, but portable scripts should avoid it.

Note: Wishing to provide a proper reference for the reader, I can not recall precisely where I obtained my DOS / Windows cmd.exe compatible version of grep (grep.exe), as there are multiple versions available. I believe it is the same as is bundled with several other useful applications in the GNU utilities for Win32 distributionโ€ . For the most authoritative resource, I recommend following the link above (near the top of the article body), which points to the Free Software Foundation web page for grep.

โ€ Update, 2010-04-02: following the URL above, as cited to point toย GNU Utilities for Win32, I encountered an HTTP authorization prompt (i.e. a dialogue window appears, asking for a username and password). Perhaps it is a temporaryย error, so try it if you wish, however the URL I have stored in the WordPressCenter.net primary links points instead to a sourceforge project titledย Native Win32 Ports of Some GNU Utilities. In my recollection, it is the same content. Weird. I could be wrong. Try the old link if you want, but I have more confidence in the Sourceforge URL.

Whatchu do

You. Yes, you!

โ€œStand still, Laddy!โ€
Don’t want to sign-in to leave a comment? Send an email with this contact form. I’m not tracking you, but I would like your opinion about what needs improving!

, ,

Leave a Reply

Your email address will not be published. Required fields are marked *