|
Filter commands help you sort, view, and select parts of a command's
output. Passing information through filter commands Filter commands divide, rearrange, or extract portions of the information
that passes through them. Windows 2000 has three filter commands:
To send input from a file to a filter command, use the less-than sign
(<). If you want the filter command to get its input from another command,
use the pipe (|). Controlling the Screen Display by Using the More Command The more command displays the contents of a file or the output of a
command one screen at a time. For example, the following more command
displays the contents of the List.txt file one screen at a time:
After a screen of information is displayed, the word "More"
appears. To continue to the next screen, press any key on the keyboard. To
stop the command without viewing more information, press CTRL+C. The more command is helpful if you are working with a command that
produces more than one screen of output. For example, suppose you want to
view a tree for your hard disk. If you have more directories than
Windows 2000 can display on the screen, you can use the tree command
with a pipe (|) and a more command, as in the following example:
The first screen of output from the tree command is displayed,
followed by the word "More." Windows 2000 pauses until you
press any key on the keyboard (except PAUSE). Searching for text by using the find command The find command searches one or more files for the text you specify.
Windows 2000 displays every line containing that text. The find command
can be used as a filter command or as a standard Windows 2000 command.
For information about using find as a standard Windows 2000
command, click find in the Related Topics list. To use find as a filter command, include a less-than sign (<)
and a file name to search through. Keep in mind that the search is case
sensitive when entering a file name. For example, the following command finds
occurrences of the string "Pacific Rim" in the file Trade.txt:
To save the output of the find command rather than display it, use
a greater-than sign (>) and the name of the file that is to store the
output. For example, the following command finds occurrences of "Pacific
Rim" in the Trade.txt file and saves them in the Nwtrade.txt file:
Sorting text files The sort command alphabetizes a text file or the output of a
command. For example, you would use the following command to sort the
contents of a file named List.txt and display the results on your screen:
In this example, the sort command sorts the lines of the List.txt
file and displays the results without changing the file. To save the output
of the sort command rather than display it, include a greater-than
sign (>) and a file name in the command. For example, you would use the
following command to alphabetize the lines of the List.txt file and store the
results in the Alphlist.txt file:
To sort the output of a command, type the command followed by a pipe (|)
and the sort command. For example, the following command sorts the
output of the find command:
When you type this command, Windows 2000 lists in alphabetic order
the lines in which the string "Jones" appears. Combining commands with redirection characters You can combine filter commands, other commands, and file names to make
custom commands. For example, you could use the following command to store
the names of files that contain the string "LOG":
Windows 2000 sends the output of the dir command through the find
filter command and stores the file names that contain the string
"Log" in the Loglist.txt file. The results are stored as a list of
file names (for example, A.log, Logdat.svd, and Mylog.bat). To use more than one filter in the same command, separate the filters with
a pipe (|). For example, the following command searches every directory on
drive C, finds the file names that include the string "Log", and
displays them one screen at a time:
Because you use a pipe (|), Windows 2000 sends the output of the dir
command through the find command. The find command selects only
file names that contain the string "Log." The more command
displays the file names that are selected by the find command, one
screen at a time. |