bug-findutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to conditionally search?


From: Eric Blake
Subject: Re: How to conditionally search?
Date: Fri, 27 Nov 2009 13:54:09 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Peng Yu on 11/27/2009 8:38 AM:
>> find . -name '*.sh' -o -name '*.py'
>>
>> ... do what you had in mind?
> 
> No. This is not what I want. This will give me all the .sh and .py
> files. But if there is a .py file and a .sh file with the same suffix

Same suffix?  How can .sh ever be the same as .py?  Oh, you meant same prefix.

> in the same directory, I only want to show the .py file but not the
> .sh file.

Try this.  It finds all *.py files and prints them, and for all .sh files,
it forks a shell that tests whether a corresponding *.py file exists in
order to decide whether to print.

find -name '*.py' -print -o -name '*.sh' \
  -exec sh -c 'test ! -f "${1%.sh}.py"' sh {} \; -print

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksQPHEACgkQ84KuGfSFAYCB1gCgpnTyWgVAu4FbADRbduFvdkuz
ugUAn3rzSWl2Yiea/BDHf4zAHKS2M5fF
=y0yd
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]