[comp.os.msdos.programmer] "finding" text in files

ted@helios.ucsc.edu (Ted Cantrall) (06/01/91)

We are getting ready to go from DOS 3.3 to 4.01 so we can use our larger
disks more effectively. As a result of having many partitions, there are
many batch files that refer to E: or F: that will have to be modified when
those partitions go away. So the question is:
 Is there any way to use DOS filters (like FIND) to print a list of the
batch files that contain an "E:" or an "F:"? The problem with useing FIND
directly is that it won't take wild cards so I'd have to manually feed it
all the batch file names. (computers are suppose to be smart) :-)

Please reply by E-Mail as I am way behind in reading news.

   Thanks to all (any) who answer...		-ted-
-------------------------------------------------------------------------------
ted@helios.ucsc.edu |"He has showed you, O man, what is good; and what does the
W (408)459-2110     |Lord require of you but to do justice and to love kindness
H (408)423-2444     |and to walk humbly with your God?" Micah 6:8 (RSV)

bingham@hpnmdla.sr.hp.com (David Bingham) (06/01/91)

Have you got a copy of 'grep' setting around? That will do it.

The alternative would be to write a fancy batch program that would
do some fancy piping. i.e. For %1 in... do this and pipe the output
into this file here....

(short pause whilst I actually look up what I'm talking about...)


	@Echo off
	FOR %%A in (%1) do find "%2" %%A >> %3

Copy that into a batch file. The calling syntax is:

	batch.bat fileset string file_name

	fileset = file to search (wildcards allowed)
	string = string you are looking for (i.e. E:)
	file_name = the file you want the results stored in

I hope that's clear. Drop me a line if it isn't.

David
************************************************************************
David Bingham		 	* The power of faith and love 
Hewlett Packard 		* Can change the stuff we're made of
bingham@hpnmqa1.sr.hp.com	*		Michael W. Smith

michaelm@ESD.3Com.COM (Michael McNeil) (06/04/91)

ted@helios.ucsc.edu (Ted Cantrall) writes:
>We are getting ready to go from DOS 3.3 to 4.01 so we can use our larger
>disks more effectively. As a result of having many partitions, there are
>many batch files that refer to E: or F: that will have to be modified when
>those partitions go away. So the question is:
> Is there any way to use DOS filters (like FIND) to print a list of the
>batch files that contain an "E:" or an "F:"? The problem with useing FIND
>directly is that it won't take wild cards so I'd have to manually feed it
>all the batch file names. (computers are suppose to be smart) :-)

I find the DOS "FIND" utility useful, even if it can't take wildcards,
by calling it from a batch file (which I call "GREP.BAT") which *is*
capable of utilizing wildcards -- through the "FOR" batch file syntax.  
Simply put a "FOR" line in your batch file, calling "FIND" like this:

	FOR %%F IN (%2 %3 %4 %5 %6 %7 %8 %9) DO FIND "%1" %%F

Then call "GREP" passing it up to eight *wildcarded* filenames, like so:

	GREP string FILE1 ... FILE8

For example,

	GREP E: D:\BIN\*.BAT

will locate all "E:" strings in batch files within the given directory.

Actually, I like putting a "SHIFT" before the "FOR" so as to pick up
one more parameter, for a total of nine.  If you do this, change the
"FOR" to take cognizance of the additional zeroth parameter, viz.:

	SHIFT
	FOR %%F IN (%1 %2 %3 %4 %5 %6 %7 %8 %9) DO FIND "%0" %%F

>Please reply by E-Mail as I am way behind in reading news.
>   Thanks to all (any) who answer...		
>
>-ted- ted@helios.ucsc.edu

--
Michael McNeil			Mail: Michael_McNeil@3Mail.3Com.COM
3Com Corporation		News: michaelm@molehill.ESD.3Com.COM
Santa Clara, California		Work telephone: (408) 492-1790 x 5-208

	If I could remember all those names [referring to
	the growing population of subatomic particles],
	I would have been a botanist.  
		Enrico Fermi, early 1950s