Article View: comp.unix.shell
Article #1550Re: csh args
From: Paul John Falstad
Date: Fri, 19 Oct 1990 21:56
Date: Fri, 19 Oct 1990 21:56
53 lines
2668 bytes
2668 bytes
In article <4864@crystal1.UUCP> mostek@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@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.
Technical Details
Message-ID:
<3467@idunno.Princeton.EDU>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!samsung!munnari.oz.au!uokmax!apple!julius.cs.uiuc.edu!wuarchive!udel!princeton!fish.Princeton.EDU!pfalstadReferences:
<4861@crystal1.UUCP> <3448@idunno.Princeton.EDU> <4864@crystal1.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!samsung!munnari.oz.au!uokmax!apple!julius.cs.uiuc.edu!wuarchive!udel!princeton!fish.Princeton.EDU!pfalstad From: pfalstad@fish.Princeton.EDU (Paul John Falstad) Newsgroups: comp.unix.shell Subject: Re: csh args Keywords: csh alias args Message-ID: <3467@idunno.Princeton.EDU> Date: 19 Oct 90 21:56:01 GMT References: <4861@crystal1.UUCP> <3448@idunno.Princeton.EDU> <4864@crystal1.UUCP> Sender: news@idunno.Princeton.EDU Distribution: comp Organization: Princeton University, Princeton, New Jersey Lines: 53