This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problems with find -exec somecommand | tosomeother command


Hi Randall,

Thanks for the explanation and the working version.  

Best,
Sheryl

--- Randall R Schulz <rrschulz@cris.com> wrote:
> Sheryl,
> 
> [ Non-Cygwin-specific ]
> 
> 
> Here's how I'd do this:
> 
>          find . -name "*.frm" -exec wc -l {} ;
> 
> 
> The result looks something like this (I changed the
> ".frm" suffix to 
> ".java" for the purpose of finding some files on my
> system):
> 
>     1114 ./DeferredUpdateKB.java
>      295 ./Definitor.java
>       93 ./FlatFormatStrategy.java
>       59 ./FormatStrategy.java
>      139 ./FormattingCursor.java
>      111 ./FormulaPrinter.java
>       77 ./FormulaRenderer.java
>     1379 ./KBContext.java
>     4503 ./KIF3.java
>      191 ./KIF3Constants.java
>      544 ./KIF3Generator.java
>      293 ./KIF3InfixPrinter.java
>     2431 ./KIF3TokenManager.java
>       91 ./LexicalGenerator.java
>     1912 ./NameTable.java
>      298 ./ParseActions.java
>      192 ./ParseException.java
>      913 ./PrefixPrinter.java
>      175 ./PrettyFormatStrategy.java
>      401 ./SimpleCharStream.java
>     1848 ./TauTest.java
>       81 ./Token.java
>      133 ./TokenMgrError.java
> 
> 
> To let you know why what you tried wasn't working,
> you must realize that 
> the pipe split the "find" command (and the "cat"
> subprocesses it spawns) 
> from the "tail" command. The "-exec" option of find
> is pretty much just a 
> means of invoking the Unix "exec(2)" system call. It
> is not like the 
> "system(3)" library routine, which uses a shell to
> interpret the command 
> string.
> 
> If you want pipelines, glob expansion or other shell
> features in the 
> commands executed by the "-exec" option, you should
> use "sh -c" or "bash 
> -c". Note, too, that in that case the command
> argument to the "-c" option 
> must be a single argument. This can get tricky as
> far as quoting and all. 
> Fortunately, the "{}" marker into which the current
> "find" target is 
> substituted does work when embedded within a larger
> string--it need not be 
> an total, isolated "find" argument.
> 
> Good luck.
> 
> Randall Schulz
> Mountain View, CA USA
> 
> 
> At 11:39 2002-10-04, Sheryl McKeown wrote:
> >Hello,
> >
> >I'm attempting to find the number of lines in each
> >file of a source directory.
> >
> >Using bash, I'm using the following command:
> >
> >find . -name "*.frm" -exec cat -n {} | tail -n1 ;
> >but it returns the error
> >
> >cfind: missing argument to `-exec'
> >tail: ;: No such file or directory
> >
> >I've tried various quoting schemes but I can't seem
> to
> >get it to work.
> >
> >I am running XP Prof SP1.
> >
> >Any help is appreciated.
> >
> >-Sheryl
> 
> 
> --
> Unsubscribe info:     
> http://cygwin.com/ml/#unsubscribe-simple
> Bug reporting:         http://cygwin.com/bugs.html
> Documentation:         http://cygwin.com/docs.html
> FAQ:                   http://cygwin.com/faq/
> 


__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]