marka@tektools.UUCP (Mark Adams) (01/28/86)
[For the Pac-Man] This is a small shell script I wrote and use quite often on my IBM-AT running MS-DOS 3.1. It does a search of one or more source files in the current directory path for a given one word string, much like the VMS search does. For example, you may want to search a file called "Sample.c" for the string "getchar" : C> search sample.c getchar A much better example is to search all of your source files for a particular string, using wildcard expansion for the filename or the extension. For example, you may want to search all files ending in ".c" for the string "getchar" : C> search *.c getchar I have the output directed to a file called "s.fnd" in my "\bin" directory, and then to the screen. That way, if I miss something, I can easily type out all the found strings again, without having to do the actual search again. This script may be copied, modified, etc., without my permission. Mark Adams Jan. 28, 1986 Tektronix, Inc. Beaverton, OR 97077 tektronix!tektools!marka To use, remove all text to and including the --Cut Here-- lines, and save into a file called SEARCH.BAT. Then place it into a directory where your system path can find it, i.e., "\bin". ----------Cut Here----------Cut Here----------Cut Here----------Cut Here------ rem Shell script SEARCH.BAT rem Usage: C> search sample.ext string - OR - C> search *.ext string rem Written by: Mark J. Adams Jan. 28, 1986 rem Permission to copy, modify, etc., by the author - MJA rem echo off echo SEARCHING FILE(S): "%1" FOR STRING: "%2" if exist c:\bin\s.fnd del c:\bin\s.fnd if not exist c:%1 goto abc for %%f in (%1) do find /n "%2" %%f >> c:\bin\s.fnd echo This file is called "s.fnd" in the \bin directory. >> c:\bin\s.fnd cls echo on more < c:\bin\s.fnd echo off goto def :abc echo FILE(S): "%1" - NOT FOUND :def echo on -----------
skip@ubvax.UUCP (Skip Addison Jr) (01/30/86)
In article <698@tektools.UUCP> marka@tektools.UUCP (Mark Adams) writes: >This is a small shell script I wrote and use quite often on my IBM-AT >running MS-DOS 3.1. It does a search of one or more source files in >the current directory path for a given one word string, much like >the VMS search does. > >For example, you may want to search a file called "Sample.c" for the >string "getchar" : > ... >For example, you may want to search all files ending in ".c" for the string >"getchar" : > ... >Mark Adams Jan. 28, 1986 > ... What about a simple for %%i in (%2) do find %1 %%i and redirect the output wherever you want it. Note the example above would be in a batch file. I usually just type it out and replace %1 and %2 with the string and filespec, and remove one of the '%' from "%%i" giving "%i": for %i in (*.c) do find "stdio.h" %i >>find.out The ">>" must be used rather than ">" or each find execution will overwrite the file. -- Skip Addison {lll-crg, decwrl, ihnp4}!amdcad!cae780!ubvax!skip
broehl@watdcsu.UUCP (Bernie Roehl) (02/05/86)
For a while now, I've been using a generalized version of this, which I call EX.BAT : for %%f in (%2) do %1 %3 %%f %4 %5 For example, ex grep bernie *.txt will grep for all occurrences of "bernie" in all .txt files in the current directory, while ex c88 \src\*.c will compile all .c files in \src.