Yahoo : Winternet : TC Guide  : Files of Local Interest Enter Sysinfo.com :


Subject: Re: find command problem
Subject: Re: find command problem
Subject: Re: Multiple File Rename


From: m.ramsch@computer.org (Martin Ramsch)
Newsgroups: comp.unix.questions,comp.unix.admin,comp.unix.shell,comp.lang.perl.misc
Subject: Re: find command problem
Date: 19 Mar 99 06:08:52 GMT
Lines: 27
Distribution: world
Mail-Copies-To: always

On 18 Mar 1999 19:50:28 GMT,
Ilya <ilya@napavlly.rose.hp.com> wrote:
> In comp.unix.admin Craig Eales <ealesc@deshaw.com> wrote:
[...]
> > find $path* -name qhelp -exec echo echo \\| {} 2\\>/dev/null \\; | sh
[...]
> It worked. Thanks. What is the second echo for and why does piping
> it to sh gets the result?

Craig's command line should be more clear written this way:

   find $path -name qhelp -exec echo 'echo | {} 2>/dev/null;' | sh

The first echo outputs a command which is read an executed from sh.
Unfortunately find's exec only does work, if the {} is a word on it's
own ...  hence the more complicated quoting you see above.


Another approach I like more in these cases is:

   find $path -name qhelp -exec sh -c 'echo | "$0" 2>/dev/null;' {} \;

Regards,
  Martin
-- 
Martin Ramsch <m.ramsch@computer.org> <URL: http://home.pages.de/~ramsch/ >
PGP KeyID=0xE8EF4F75 FiPr=52 44 5E F3 B0 B1 38 26  E4 EC 80 58 7B 31 3A D7

-- 


From: ken@halcyon.com (Ken Pizzini)
Newsgroups: comp.unix.questions,comp.unix.admin,comp.unix.shell,comp.lang.perl.misc
Subject: Re: find command problem
Date: 18 Mar 1999 19:22:55 GMT
Lines: 50
Reply-To: ken@halcyon.com
User-Agent: slrn/0.9.5.3 (UNIX)

On 18 Mar 1999 06:29:35 GMT, Ilya <ilya_NOSPAM_@napavlly.rose.hp.com> wrote:
>I can do the following at the prompt:
>
> > echo | /opt/robelle/bin/qhelp     
>QHELP/UX/Copyright Robelle Consulting Ltd. 1981-1995
>(Version 2.1.05)
>
>Enter the help filename? 
> >

Can you also do this with:
  $ /opt/robelle/bin/qhelp </dev/null
?


>I would like to accomplish the same task programmatically, using the find in a
>Perl script:
>
>$lines = `find $path* -name qhelp -exec echo | {} \\; 2>/dev/null`;
...
>Any tips on how to handle "|" in the find command used in Perl script?

It's not a perl problem, it's a find problem.

First, to have find see the |, you need to quote it from the shell:
 $lines = `find $path* -name qhelp -exec echo \\| {} \\; 2>/dev/null`;

But that won't do what you want either, as now find is calling echo
with the arguments "|" and "{}".


To have the pipe executed you need to have find invoke a subshell
to set up the pipeline:
 $lines = `find $path* -name qhelp -exec sh -c 'echo \\| {}' \\; 2>/dev/null`;

But if you have very many qhelp executables this can get expensive.
So, if the </dev/null test above works for you, this can become:
 $lines = `find $path* -name qhelp -exec {} \\; </dev/null 2>/dev/null`;


That's pretty good.  But now let's step back a second and reconsider
the fact that we're running this from within perl.  In that case we
can use File::Find to simplify things:
  use File::Find;
  $lines = '';
  find(\&tryit, glob("$path*"));
  sub tryit {/^qhelp$/  and  $lines .= `echo | $File::Find::name 2>/dev/null`}


		--Ken Pizzini

-- 


Newsgroups: comp.unix.questions
From: Paul <Paul.J.Shirron@boeing.com>
Subject: Re: Multiple File Rename
Mime-Version: 1.0
Date: Mon, 3 May 1999 10:58:36 GMT
Lines: 18

@í wrote:
> 
> I know there is an easy way to rename a bunch of files in subdirectories
> with the find command, but I'm kind of stumped. I tried the following:
> 
> find . -name "index.html" -exec mv '{}' index.shtml
> 
> But all I get is an error that the -exec parameter is asking for more..
> anyone know how this silly find command works?
> 
> Ted Smith
> mailto:tsmith@computing-platforms.com

The exec command needs a terminator, usually an escaped semicolon,
like this:

find . -name "index.html" -exec mv '{}' index.shtml \;

-- 

Yahoo : Winternet : TC Guide  : Files of Local Interest Enter Sysinfo.com :



Hosted by: Enter:  sysinfo.com


©copyright 1995-2002 sysinfo.com