Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question RE find using grep

Status
Not open for further replies.

fabien

Technical User
Sep 25, 2001
299
AU
Hi!

In ly script I would like to be able to copy all the files from a given directory except a few with given extension.

For now I use the command find . -print | cpio -pdvmu, how can I discard files based on extension *.bri* for instance?

Thanks!
 
Try this:
Code:
find . ! -name '*.bri*' -print | cpio -pdvmu

Hope This Help
PH.
 
You can do :

find . -print | grep -v '*\.bri*' | cpio -pdvmu

Jean Pierre.
 
Thanks guys, if I have several file extensions do I put a comma between them?
 
With find only:
Code:
find . ! -name '*.bri*' ! -name '*.ext2' ! -name '*.ext3' ... -print | cpio -pdvmu
with grep -E (or egrep):
Code:
find . -print |
 grep -E '\.bri|\.ext2|...|\.extN' |
  cpio -pdvmu

Hope This Help
PH.
 
Correction:

find . -print | egrep -v '.*\.bri.*' | cpio -pdvmu

To exclude extensions bri, brj and brk :

find . -print | egrep -v '.*\.(bri|brj|brk).*' | cpio -pdvmu

Jean Pierre.
 
Jean Pierre, you don't need the leading and trailing '.*'.
Sans offense, j'espère :)
PH.
 
Ok it works fine but I would like to include also files toto.* as well *.bri.* in one go is it possible?
 
In the find only version, simply insert this:
Code:
! -name 'toto.*'
Try this if egrep:
Code:
grep -E '\.bri$|\.ext2$|...|\.extN$|^toto\.'

Hope This Help
PH.
 
This did not work, with egrep -v (grep -E does not work) I still get the toto.a toto.b etc selected..
 
To exclude files toto.* and *.bri.* :

egrep -v '^toto\.|\.bri\.'
[tt]
-v <= Exclude selected lines
<= Select lines
^toto\. <= starting with toto.
| <= or
\.bri\. <= containing .bri.
[/tt]

Jean Pierre.
 
fabien, remove the ^ at front of toto
Et ça va marcher.

Hope This Help
PH.
 
Fabien
Please post the complete line that did not work, and tell us what did not work, syntax or results.
Merci

 
The command does'nt work because filename are prefixed by the directory path : ./ ... /filename

A solution :

tar . -print | egrep -v '/toto\.|\.bri\.' | cpio -pdvmu

There is a problem with this egrep command.
If your directory contains sub-directory with name starting with toto. or containing .bri. all its files will be ignored :
./test/toto.datas/a.a
./in.bri.new/lulu.txt

Another solution :

tar . -print | egrep -v '\(/toto\.|\.bri\.\)[^/]*$'| cpio -pdvmu


Jean Pierre.
 
Even better:
egrep '\.bri$|\.ext2$|...|\.extN$|/toto\.'

Hope This Help
PH.
 
PHV's worked like a charm, thanks guys!

Why do you need to have \. at the end? Does it apply to all expressions in front of it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top