Jump to content

looking for a bash directive


Recommended Posts

Hi,

 

Im trying to create a script which will process a whole directory tree but skip processing files which contains certain characters. Can somebody tell me how to make bash (or another utility that has a cygwin port) a directive that is something like "skip file if filename contains the character X, otherwise process it with the rest"? thanks.

 

ciao!

Link to comment
Share on other sites

i might be missing it but i dont think this would help. im basically doing a directory walker. it will list the contents of the specified directory and process each entry. if the entry is a regular file then the script will pass it off to another utility for further processing but if it is a directory then it will process it again by listing its contents and so on until the directory structure has been processed.

 

thanks anyway.

 

ciao!

Link to comment
Share on other sites

I have php scripts that do that sort of thing if you want i could post some examples.

 

For example i have one that searches through all directories from a specifiec base directory and finds all pdf files then runs ps2ascii on all the pdfs via shell_exec().

Link to comment
Share on other sites

the 'find' command piped through to the processing command may be able to accomplish this. Something like

 

$ find . -name * | cat

 

Or some variation thereof may do what you need. There are several switches for find that will limit it to only looking at regular files and it acts recursively by nature so therefore, will process all files below the directory you specify.

 

Otherwise, perl or ruby or python may be the next best solution for what you are looking for.

Link to comment
Share on other sites

thanks guys. the script is pretty much stable at the moment with the added quirk that it processes the *$* files as well. fwiw, i am decompiling a directory of classes for review and i dont technically need to decompile inner classes. ill take a look at the find solution (assuming i can figure out the correct regexp, being regexp is one of the weakest linux skills).

 

ciao!

Link to comment
Share on other sites

Couldn't you just use a for loop and the test command?  That said you'd still need reg expressions.

i am using a for loop+test combo. what i cant figure out is how to test the existence of the dollar sign in the name of the file i am currently processing.

 

ciao!

Link to comment
Share on other sites

would a regexp of something like /.*\$.*/ not match anything with a dollar in it?

probably, but how do i integrate that with the test built-in? my only problem is that using that with find will entail me to do some more cutting on the path. but i will consider that until something better comes up. thanks.

 

ciao!

Link to comment
Share on other sites

Hmm, I have no idea if test works with regexps so maybe it's best to dump that idea. Incidently is it not a little foolish to have files with a $ in the name, bash will want to expand the $ as a variable.

 

I've suddenly realised this is a bit easier than I thought, just use grep - pipe the current filename to

 

grep '\$'

 

which will match anything with a dollar in, if the return is zero process the file (or whatever you want to do with it) otherwise skip

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...