Using filters
Updated: January 21, 2005
Filter commands divide, rearrange, or extract portions of the information that passes through them. The following table lists filter commands that are available in the Windows Server 2003 family.
Command | Description |
More | Displays the contents of a file or the output of a command in one Command Prompt window at a time. |
Find | Searches through files and command output for the characters you specify. |
Sort | Alphabetizes files and command output. |
To send input from a file to a filter command, use a less than sign (<). If you want the filter command to get input from another command, use a pipe character (|).
Using the more command
more < list.txt
One Command Prompt window of information appears, and then the -- More -- prompt appears at the bottom of the Command Prompt window. To continue to the next Command Prompt window, press any key on the keyboard except PAUSE. To stop the command without viewing more information, press CTRL+C.
You can use the more command when you work with a command that produces more than one Command Prompt window of output. For example, suppose you want to view a directory tree on your hard disk. If you have more directories than can be displayed in the Command Prompt window, you can use the tree command with a pipe character (|) and the more command as follows:
tree c:\ | more
The first Command Prompt window of output from the tree command appears, followed by the -- More -- prompt. Output pauses until you press any key on the keyboard, except PAUSE.
Using the find command
To use find as a filter command, you must include a less than sign (<) and the string or text on which you want to search. By default, find searches are case-sensitive. For example, the following command finds occurrences of the string "Pacific Rim" in the file Trade.txt:
find "Pacific Rim" < trade.txt
The output does not include any occurrences of "pacific rim." It includes occurrences of the capitalized "Pacific Rim" only.
To save the output of the find command rather than display it in the Command Prompt window, type a greater than sign (>) and the name of the file where you want to store the output. For example, the following command finds occurrences of "Pacific Rim" in the Trade.txt file and saves them in Nwtrade.txt:
find "Pacific Rim" < trade.txt > nwtrade.txt
Using the sort command
sort < list.txt
In this example, the sort command sorts the lines of the List.txt file into an alphabetical list and displays the results without changing the file. To save the output of the sort command rather than display it, type a greater than sign (>) and a file name. For example, the following command alphabetizes the lines of the List.txt file and stores the results in the Alphlist.txt file:
sort < list.txt > alphlist.txt
To sort the output of a command, type the command, type a pipe character (|), and then type sort (that is, Command | sort). For example, the following command sorts the lines that include the string "Jones" (that is, the find command output) in alphabetical order:
find "Jones" maillst.txt | sort