I/O Redirection and Filters, or Making DOS Jump Through Your Hoops . . . By Ken Johnson, Chicago Computer Society Many personal computer users never move beyond the basic DOS commands they learned with their first computer -- the famous DIR, COPY, ERASE, CHKDSK, and (infamous) FORMAT. But once you begin to look a little further into DOS, you can find all sorts of interesting tricks to make you computing life faster and easier. This article will look at two of the most interesting "advanced" uses of DOS: Input/Output redirection and the DOS filters. Input/Output Redirection I/O Redirection simply means to redirect input to and output from a DOS command or program. Normally DOS gets it's input from the keyboard and directs it's output to the screen. But by using the greater than (>), less than (<), and pipe (|) symbols, you can have DOS use a different input source and output destination. COMMAND > FILENAME -- sends the screen output of that command to the file specified. Think of the ">" here as indicating "with output to." COMMAND >> FILENAME -- adds lines of output to the existing file specified. The ">>" indicates "append output to." (Note: if the file specified by "FILENAME" does not exist, DOS will create it). COMMAND < FILENAME -- contents of the file specified is the input of the command. Here the "<" indicates "with input from." COMMAND | COMMAND -- "pipes" the output of the first command as input to the second command. This redirection is invisible to the command or program. The command or program always reads from the keyboard and writes to the screen. With I/O redirection, you are changing the definition of "keyboard" and "screen". I/O redirection can work with all DOS commands, but is used most often with three special DOS programs called filters -- MORE.COM, SORT.EXE, and FIND.EXE. These DOS filters can process text files or DOS command output through I/O redirection. You also can use I/O redirection with DOS' ECHO command to send control characters to your printer. For information on this use of redirection, see George Kollar's article "Printer Setup Codes" in the January 1991 issue of HardCopy. Some examples of redirection: DIR > FILELIST.TXT -- This creates a text file with your directory listing in it. This file can now be TYPEd, PRINTed, or edited with any text editor. DIR | SORT -- The DIR sends it's output to the SORT filter, which will sort and display the file names alphabetically. VER >> PCINFO.TXT CHKDSK C: >> PCINFO.TXT TREE C: >> PCINFO.TXT -- This sequence of commands will write information about the PC to a textfile called PCINFO.TXT. This file will contain the DOS version (VER), information on the hard drive and memory (CHKDSK), and finally a listing of directories on the hard drive (TREE). DIR | SORT | FIND /V "i" > SORTDIR.TXT -- This is an interesting one! The DIR command sends it's output to the SORT filter, which sorts the file names. SORT then sends it's output to the FIND filter, which removes all lines containing a lower-case "i" (this removes some lines that don't contain file names). Finally, the output of the FIND filter is sent to a file called SORTDIR.TXT. (The SORT and FIND filters are explained below). DIR | SORT | FIND /V "i" > PRN -- This also creates a sorted list of your files, but sends the result to the printer. PRN is the DOS device name for the printer. One note when you redirect the output of the DIR command. You probably will see two zero-byte files listed with names like "0E0C314F". These are generated temporarily as holding areas for the standard I/O. The files are always created in DOS' default directory, so one way to avoid them is to make a different drive the default before issuing the redirected DIR command. FIND filter The multitalented FIND filter will find lines in a file that contain (or don't contain) a string you specify, and optionally show you the line number of that string or a count of matching lines. The syntax of the command is: FIND [/V] [/N] [/C] "string" filename [filename . . .] "string" is the sequence of characters you wish to find in the file specified; it must be an exact match (upper and lower case ARE different). /V is a reVerse FIND; only output lines that DON'T contain the string. /N outputs a line Number before each matching line. /C outputs only a Count of matching lines, not the text of the lines. Let's look at some examples: FIND /N "Do Case" MENU1.PRG MENU2.PRG -- displays all lines of the files MENU1.PRG and MENU2.PRG that contain the character string "Do Case". Because of the /N switch, the line number will be displayed before the text of each line found. DIR C:\ | FIND "<" -- will display the subdirectories in the root directory of your hard drive (which have a