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

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...