Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Beginning Regular Expressions 2005.pdf
Скачиваний:
95
Добавлен:
17.08.2013
Размер:
25.42 Mб
Скачать

 

 

Regular Expressions Using findstr

 

 

 

 

 

 

 

Hexadecimal Number

Color Specified

 

 

 

 

B

Light aqua

 

C

Light red

 

D

Light purple

 

E

Light yellow

 

F

Bright white

Some combinations either make no sense, such as white text on a white background, or are ignored. For example, if you type

findstr /n /i /a:00 “ABC[0-9]” Orders*.txt

which specifies black text on a black background, the normal white on black is used. Some other combinations, such as the following for blue text on a blue background

findstr /n /i /a:11 “ABC[0-9]” Order*.txt

are allowed but are essentially useless, unless you simply want a block of color to be displayed at the beginning of a line that contains a match.

Figure 13-17 shows the on-screen appearance of some of the possible arguments for the /a switch.

Figure 13-17

Single File Examples

The following examples also illustrate usage of the findstr utility. The findstr utility is limited in the quantifiers that it supports, which tends to limit what it can effectively be used for.

319

Chapter 13

Simple Character Class Example

This example will use the sample file gray.txt to demonstrate the use of the findstr utility. The content of gray.txt is shown here:

gray grey greying greyed grapple grim goat filigree great groat gloat Gray Grey

The problem definition is as follows:

Match a g followed by an r, followed by a choice of e or a, followed by y.

The pattern gr[ae]y contains a simple character class that allows the desired text to be matched.

Try It Out

Simple Character Class Example

1.Open a command window, and navigate to the directory that contains Gray.txt.

2.At the command prompt, type the following command:

findstr /n “gr[ae]y” Gray.txt

3.Inspect the results, as shown in Figure 13-18.

Figure 13-18

Find Protocols Example

This example illustrates a simple technique to find Internet protocols. The content of the sample text

Protocols.txt is shown here:

http://www.w3.org/

ftp://www.XMML.com/

mailto:someone@example.org

320