Wildcards and exceptions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Wildcards and exceptions
# 8  
Old 03-12-2013
Note that ksh and bash also support extended globbing.
The syntax is different from the one Chubler_XL mentioned;
zsh actually supports both (see the ksh_glob option).
With bash (adding archive to the exclude list for obvious reasons):
Code:
shopt -s extglob
mv -v -- !(@(README.txt|archive)) archive

[drop the -v switch, if your mv implementation doesn't support it]
The syntax above originates from the ksh, where it's enabled by default.

PS: The code won't work correctly when there are no matching files.

Last edited by radoulov; 03-12-2013 at 06:48 PM..
# 9  
Old 03-12-2013
I seem to recall *cp -r uses cpio, so:
Code:
find ... | grep -v 'unwanted' | cpio -i... | ( cd dest ; cpio -od... )

# 10  
Old 03-12-2013
I think the OP only wants to match directories.

I don't think bash/ksh extended globbing has an equivalent of the (/) glob qualifier

Edit: Nice DGPickett, I had something similar in mind, with an xargs at then end of the pipe, but I gave up on that when I realized the OSX mv doesn't support -t DIRECTORY

Last edited by Chubler_XL; 03-12-2013 at 06:25 PM..
# 11  
Old 03-12-2013
Quote:
Originally Posted by Chubler_XL
I think the OP only wants to match directories.

I don't think bash/ksh extended globbing has an equipment of the (/) glob qualifier
Sorry for not reading carefully.
All shells have <glob>/:

Code:
$ mkdir archive dir{1..3}
$ touch file{1..3} README.txt
$ shopt -s extglob
$ mv -v -- !(@(README.txt|archive))/ archive
`dir1/' -> `archive/dir1'
`dir2/' -> `archive/dir2'
`dir3/' -> `archive/dir3'

This User Gave Thanks to radoulov For This Post:
# 12  
Old 03-12-2013
Actually, if README.txt is not a directory, this should be sufficient (extended glob is not needed):
Code:
mv -- */ archive

To get rid of the error message about moving the archive directory (and if 2>/dev/null is not an option, because the
exit status is important), with extended glob:
Code:
shopt -s extglob
mv -- !(archive)/ archive

Note that you may need to add some code/option to handle the case when no directory matches
or when you want to include hidden directories.

Last edited by radoulov; 03-12-2013 at 06:46 PM..
# 13  
Old 03-13-2013
I believe I saw a similar subtree copy utility with tar, but it did not have a way to exclude files. Havng the file list allows you to do tricky things like sorting by extension and then by path so similar files hit a compressor in the middle before an ssh/rsh to another host over the network where you decompress and cpio -o. It optimizes the compression that effectively multiplies the network speed. I like the simple, modular tools, but you can do something similar with rsync using 'ssh -C -o CompressionLevel=9'. Looking at the man, I see rsync allows you to exclude files, and it says GNU tar does, too: Man Page for rsync (all Section 0) - The UNIX and Linux Forums
# 14  
Old 03-13-2013
Quote:
Originally Posted by Corona688
You don't have maxdepth, then unfortunately.
-maxdepth is available in OS X's find.

Code:
$ sw_vers -productVersion                      
10.8.2

$ man find | col -b | grep -A1 -- -maxdepth    
     -maxdepth n
	     Always true; descend at most n directory

This User Gave Thanks to Scott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

RegEx with exceptions

I am totaly new to RegEx, but I need to extract emails with RegEx from text file Some difficulties: 1. “@”symbol has been substituted for “ at ”,"AT" or "(at)" 2. I do not need any email with domain "myoldcompany" I found that with these I can found any emails: "^+@+\.+$" How to do... (1 Reply)
Discussion started by: AIX_30
1 Replies

2. IP Networking

SIGUP Exceptions during the execution

hello, I am getting SIGUP Exceptions during an execution of a procedure. Below is the log: Type: SignalException Message: SIGHUP Backtrace: 12:38 PM Action threw an exception: SIGHUP 12:38 PM Action threw an exception: SIGHUP E, ERROR -- : Type: SignalException Message: SIGHUP... (1 Reply)
Discussion started by: Deepthi.Prakash
1 Replies

3. Programming

Relationship between exceptions and signals

Hi everyone, I am using AIX 6.1. There are exception codes defined in header file sys/m_except.hAlso, in the documentation (in "Understanding exception handling") it says: If no exception handler is currently defined when an exception occurs, typically one of two things happens. If... (0 Replies)
Discussion started by: manolo123
0 Replies

4. UNIX for Dummies Questions & Answers

Diff with exceptions Question

So I'm currently developing an automated test system and I'm verifying my results by running a set of baselined data through and comparing the output (which is in a txt file) to a baseline results file. So of course I'm just using the diff command. Unfortunately each time I run the test there are 2... (3 Replies)
Discussion started by: Smitty0881
3 Replies

5. UNIX for Advanced & Expert Users

java Exceptions color

Hi, I call a java program from a cron job and i need to display the exceptions or Errors thrown by java(basically stacktrace) in the unix/linux console in the red color.Is it possible to do that? If so, pls. give me some pointers how to do that. eg: Exception in thread "main"... (0 Replies)
Discussion started by: ramse8pc
0 Replies

6. UNIX for Dummies Questions & Answers

Change Uppercase to Lowercase with some exceptions

I need to change instances of uppercase to lowercase. The change occurs only when all of the characters are capital letters. For instance, if the following was contained in the file: THE BRIGHT DAY it should be: the bright day However: The BRIGHT day should remain the same. Also, if it were... (3 Replies)
Discussion started by: kcgb20
3 Replies

7. Shell Programming and Scripting

Remove directory with exceptions

Hi, I want to remove a directory recursively except the inside directories calles .SYNC (designsync dirs) I am looking for something like: \rm -rf < find . * | grep -v .SYNC The find works ok but I do not know how to redirect it. Please help. Regards, Ziv (3 Replies)
Discussion started by: zivsegal
3 Replies

8. UNIX for Advanced & Expert Users

Remove directory with exceptions

Hi, I want to remove a directory recursively except the inside directories calles .SYNC (designsync dirs) I am looking for something like: \rm -rf < find . * | grep -v .SYNC The find works ok but I do not know how to redirect it. Please help. Regards, Ziv:rolleyes: (1 Reply)
Discussion started by: zivsegal
1 Replies

9. Solaris

Java Exceptions while installing Oracle

Hello. I was trying to installe oracle 10g on solaris t0 x86 and got few exception? Could you please suggest, what might be going wrong? $ ls -l total 32 drwxr-xr-x 9 oracle dba 512 Nov 21 03:50 doc drwxr-xr-x 5 oracle dba 512 Nov 21 03:50 install drwxr-xr-x 2... (5 Replies)
Discussion started by: panchpan
5 Replies

10. Shell Programming and Scripting

exceptions in import

Hello, I want to import an Oracle database file on my fresh DB, bought before successfully with exp command. But is it possible to import some tables from the dmp file, because they are too large and it's so long !? I didn't find any option in imp command to make exception on certain tables...... (1 Reply)
Discussion started by: madmat
1 Replies
Login or Register to Ask a Question