csh args

Paul John Falstad pfalstad at fish.Princeton.EDU
Sat Oct 20 07:56:01 AEST 1990


In article <4864 at crystal1.UUCP> mostek at motcid.UUCP (Frank B. Mostek) writes:
>One example is a search alias :
>alias	sea	'find \!:1 -name "\!:2" -print -exec grep \!:3 {} \;'

Right, this works.  For example, "sea . *.c main".

>Other things I would like to do would be to only "print" the files that grep
>finds a pattern in, and pipe the grep into more.
>
>The following alias does not work:
>
>alias	sea	'find \!:1 -name "\!:2" -print -exec grep \!:3 {} | more \;'

No it doesn't, for several reasons.  First of all, you forgot to escape
the |.  The shell was interpreting that whenever you executed the alias.
I assume you wanted the | passed to find, because you put a \; after it.
Second of all, even if you did escape the |, this wouldn't work because
find does not accept shell metacharacters.  It would just stupidly pass
the | and more to grep as filenames.

Also, I'm not sure this does what you want.  It runs more once for each
file it finds a string in (rather inefficient) and it prints the names
of all files that match the pattern, not just the ones that have the
string in them.

Try:

alias sea 'find \!:1 -name "\!:2" -exec grep \!:3 {} \; -print | more'

Although that prints the lines matched and THEN the file, if that's
acceptable.  Or you could try:

alias sea 'find \!:1 -name "\!:2" -print | xargs grep \!:3 | more'

I suggest removing the double quotes around \!:2; they're rather
confusing.  Something like "sea . *.c main" implies that you want the
shell to expand the *, which is not what happens.

You probably can't get EXACTLY what you want without writing either a
shell script or a ridiculously large alias.

#! /bin/sh
for i in `find "$1" -name "$2" -print | xargs grep -l "$3"`
do
	echo $i
	grep "$3" $i
done | more

--
Paul Falstad, pfalstad at phoenix.princeton.edu PLink:HYPNOS GEnie:P.FALSTAD
And Dinsdale said, "You've been a naughty boy, Clement," and splits me nostrils
open, and saws me leg off, and pulls me liver out.  And I said, "My name's not
Clement."  And then he loses his temper.  And he nails me head to the floor.



More information about the Comp.unix.shell mailing list