DOSKEY Macro to Search for File Text

This article was previously published under Q74038
This article has been archived. It is offered "as is" and will no longer be updated.
The following DOSKEY macro searches all files in the current directoryfor the message text specified and displays the output a screen at atime. Any type of file will be searched, regardless of the file'sextension. When the macro is executed, the name of each file beingsearched will be displayed along with the macro command. The macrooutput will be displayed one screen at a time, which you can examineto locate the message text you are searching for. Finally, the file"output" is deleted so that when using the macro again, the fileoutput only represents one message search.

To create this macro, enter the following at the command prompt:
doskey search=for %a in (*.*) do c:\dos\FIND /i "$*" %a
$g$g output $t type output $b c:\dos\MORE $t del output
(Do not press ENTER until you have entered the whole macro.)

To run this macro, type:
SEARCH message
The message does not require quotation marks and is not casesensitive. The output of the search is displayed one screen at a time.If the text is found, a line with the text will appear below the file.Make sure the FIND and MORE commands in the above search macro arereferencing the MS-DOS 5.0 directory. Also, by using the FIND /iswitch, the message search will not be case sensitive.
More information
For example, the following macro searches for the text "No availableextended memory" in the current directory and displays the partialresult of the command.

First, change to the DOS directory that includes HIMEM.SYS, then enterthe following command:
SEARCH no available extended memory
The following output appears:
---------- HIMEM.SYS
ERROR: No available extended memory was found.
The file the text was found in was HIMEM.SYS. The line that includesthe message starts with "ERROR:..."

A search with the abbreviated "message" field, such as "extendedmemory," will result in the same output as above. To make the messagesearch case sensitive, remove the FIND /i switch.

To use this macro every time you start your system, include thefollowing command in your AUTOEXEC.BAT file:
   doskey search=for %%a in (*.*) do c:\dos\FIND /i "$*" %%a   $g$g output $t type output $b c:\dos\MORE $t del output				
Notice that this batch file command is different from the previouscommand that is inserted at the command prompt. The difference is thatan additional % (percent sign) is included before each "%a" so thatthe "%a" will be recognized.


"Microsoft MS-DOS User's Guide and Reference," version 5.0, pages175-181, 448-453
5.00 noupd

Article ID: 74038 - Last Review: 10/26/2013 13:39:00 - Revision: 2.0

  • Microsoft MS-DOS 5.0 Standard Edition
  • kbnosurvey kbarchive KB74038