Grep Sample

Sample Overview

This sample implements a simple grep text search sample utility.  This sample demonstrates the use of regular expression functionality and the System.Text.RegularExpressions.Regex class.

Usage

ngrep [-ismqleEt?] [-r replacePattern] pattern [files [files ...]]

The following table shows the command-line options used by the sample.

Option Description
-? Shows usage information.
-e Shows only the part of the line matching the expression, not the whole line.
-E Shows original and replacement expressions (with -r). Expressions are separated with "" -> "".
-i Ignores case in search.
-l Shows lines only. Prevents showing filename or line number. Cannot be used with -m option.
-m Shows only file names, not matching lines.
-q Specifies quiet mode. Shows only summary data.
-r Replaces all matches with the given pattern.
-s Recurses into subdirectories.
-t Pretends to replace, but does not actually modify the file. Use with the -r option.

Sample Source and Build Output Locations

The sample source is found in sscli\samples\utilities\grep. 

The source file is:

The build output location is %TARGETCOMPLUS%\samples\utilities\grep.  The output file is an executable assembly named ngrep.exe.

Building the Sample

All samples are built from the buildall script. 

You can also build all the samples by switching to the root of the sample directory, sscli\samples, and typing build -c.

You can build this specific sample by switching to the sample directory and typing build -c.

Running the Sample

These steps require that the Shared Source CLI (SSCLI) be already built and functional.

  1. Run env.bat or source the env.csh or env.sh script files, depending on your platform.
  2. Switch to the %TARGETCOMPLUS%\samples\utilities\grep directory.
  3. Type the following command:

    clix ngrep.exe pattern filename

where pattern is a regular expression search pattern and filename is the name of the file to search.


Copyright (c) 2002 Microsoft Corporation. All rights reserved.