[TriLUG] help converting a perl script to zshell

Aaron S. Joyner aaron at joyner.ws
Tue Apr 13 19:55:29 EDT 2004


One question about your perl code -- what does $files; do and why do you 
have $dirty as part of your string?  Neither are doing anything, I would 
guess that they're left-overs from some previous iteration where you 
were testing or doing something else in particular?

If your description is correct, and you just want to a list of files 
with meta characters in the name, that's actually quite easy to do by 
chaining together a few common *NIX utilities - consider this:
file /your/directory | grep '[*?%$@#^!()]'
That will give you a list of every file which contains a character in 
the big gobbeldeygook of special characters.  You may of course add and 
remove them at will, as long as you leave the []'s, and don't put a ^ as 
the first character after the [, or it will match precisely the opposite 
of what you expect.  If you want to accomplish the same task in pure 
zshell (say for inclusion on a tiny distro or something), then more 
thought will be required.  I don't do that much thought unless it's 
really required.  :)  Unless zsh has support for regex's or some pretty 
good pattern matching or substitution, it's going to be difficult, at 
best. 

Okay I don't know much about zsh so I got curious.  A quick skim of "A 
User's Guide to ZSH" turned up that you could probably do what you want 
with a zsh pattern match like this:
[^[:alpha:][:digit:]-/.]
getting the list of files into a zsh variable, and the rest of the 
fluff, is left as an exercise to the reader (think: @dir = `ls`).

Aaron J.

Smith, Brett wrote:

>Guys~
> I need some help with a zshell script. I have searched the web and just
>haven't found an answer.  I am trying to match metacharacters in filenames
>(on my ftp server) so I can mark them as bad and move them. I have
>everything else done in zsh. 
>I have the perl code to do it but I really need to convert it to zsh (or
>even bash). Here is the perl code.
>#!/usr/bin/perl
>$dir = shift(@ARGV);
>$glob = ($dir) ? $dir . "/*" : "*";
>while (<${glob}>) {
>$files;
>$file = $_;
>s/\w+//g;
>s/[\.\-\/]//g;
>print $dirty . " $file\n" if ($_ ne "");
>}
>If anyone knows the answer or could help point me in the right direction I
>would appreciate it. (zsh IRC channel on freenode was devoid of human
>interaction)
>Thanks,
>
>Brett Smith
>IS Team 
>Bloodhound, Inc.
>2520 Meridian Parkway, Suite 500
>Durham, N.C.  27713
>(919) 313-1619
>bsmith at bloodhoundinc.com
>
>Brett Smith
>IS Team 
>Bloodhound, Inc.
>2520 Meridian Parkway, Suite 500
>Durham, N.C.  27713
>(919) 313-1619
>bsmith at bloodhoundinc.com
>
>
>
>This email message is for the sole use of the intended recipients(s) and may contain confidential and privileged information of Bloodhound Software, Inc.. Any unauthorized review, use, disclosure is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
>  
>




More information about the TriLUG mailing list