From owner-freebsd-questions Thu Sep 19 5:44:11 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 628F237B401 for ; Thu, 19 Sep 2002 05:44:06 -0700 (PDT) Received: from ncsmtp03.ogw.rr.com (ncsmtp03.ogw.rr.com [24.93.67.84]) by mx1.FreeBSD.org (Postfix) with ESMTP id B71BC43E4A for ; Thu, 19 Sep 2002 05:44:05 -0700 (PDT) (envelope-from bts@fake.com) Received: from mail5.nc.rr.com (fe5 [24.93.67.52]) by ncsmtp03.ogw.rr.com (8.12.5/8.12.2) with ESMTP id g8JBvWiZ027614; Thu, 19 Sep 2002 07:57:32 -0400 (EDT) Received: from this.is.fake.com ([24.162.238.30]) by mail5.nc.rr.com with Microsoft SMTPSVC(5.5.1877.757.75); Thu, 19 Sep 2002 07:57:34 -0400 Received: by this.is.fake.com (Postfix, from userid 111) id 9B386BA12; Thu, 19 Sep 2002 07:57:23 -0400 (EDT) From: "Brian T. Schellenberger" To: Peter Leftwich , FreeBSD LIST Subject: Re: find case-insensitive challenge Date: Thu, 19 Sep 2002 07:57:21 -0400 User-Agent: KMail/1.4.2 References: <20020919013548.H83658-100000@earl-grey.cloud9.net> In-Reply-To: <20020919013548.H83658-100000@earl-grey.cloud9.net> MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="------------Boundary-00=_L7POY5N4J9GXWY9SX6KQ" Message-Id: <200209190757.22640.bts@babbleon.org> Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --------------Boundary-00=_L7POY5N4J9GXWY9SX6KQ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit On Thursday 19 September 2002 01:38 am, Peter Leftwich wrote: | Tonight I surprised myself by running `find ~/Desktop/folder/ -name | "*.jpg" -exec mv {} ~/Desktop/folderjpgs/ \;` successfully! My first | custom find command line ever. | | But there were two issues -- I had to escape the semicolon with a "\" Yes, it always works that way. | -- does this ever cause problems for find command lines? No, not really. | Second, | this found only *.jpg files and left behind *.JPG files so how do you | make find be case-insensitive? find ~/Desktop/folder/ \( -name "*.jpg" -o -name "*.JPG" \) \ -exec mv {} ~/Desktop/folderjpgs/ \; Actually, what *I* do is avoid having files with capital letters in them, or spaces, or &'s, or any of those other goofy characters you sometimes find in Windows file names. Then I don't have to do the above. I accomplish that with the attached pair of scripts, though there are no doubts lots of other nice ways to do this. (I run the "unmsdos" script over files that I download from the web or newsgroups or what-have-you. It makes all of file names "Unix-friendly" and, if the file is a text file, it invokes uncrnl to change the cr-nl's at the ends of lines into just plan nl's.) | -exec ThankYouScript.sh {} \; -- Brian, the man from Babble-On . . . . bts@babbleon.org (personal) --------------Boundary-00=_L7POY5N4J9GXWY9SX6KQ Content-Type: application/x-perl; name="unmsdos" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="unmsdos" #! /usr/bin/perl # # By Brian T. Schellenberger (bts@babbleon.org) # Please maintain this credit but otherwise, use as you see fit. # (If it gets substantially transmorgified, it would probably be # best to just say "based on . . . " # if ($ARGV[0] eq '-c') # Special CD-ROM mode { $cdrom = 1; } if ($ARGV[0] eq '-n') { shift; $putname = 1; } foreach (@ARGV) { # unmsdos accpets a "quoting" convention of angle-brackets to # quote names. If it has 'em, strip 'em. If it has the leading, # but not the trailing, bracket then save this one and come # around again. First see if we are continued from before. if ($pending) { $_ = $pending . ' ' .$_; $pending = ""; } if (/^$/) { s/^$//; } else { $pending = $_; next; } } $path = $_; $path = "." if (! /\//); $path =~ s|/[^/]*$||; s|^.*/||; $newname = $_; if ($cdrom) { next if (length > 12 || /[a-z]/); # 12 = 8.3 (12345678.ABC) goto justLowercase; } # If it's one of my "rated" names, seperate out the rating part. # Always take out leading paths for file renames. $prefix = ""; if (/^(.*\/)?(\w+-\w+-\w+:)?/) { $prefix = $&; $_ = $'; } # name conversions. $newname =~ tr/\x80-\xFF/\x00-\x7F/; $newname =~ s/[\x00- ]/_/g; $newname =~ s/[[\]]/_/g; $newname =~ s/\&/+/g; $newname =~ s/\s/_/g; $newname =~ s/^~/_/g; $newname =~ s/^\+/p_/g; $newname =~ s/([^.])~/$1-/g; $newname =~ s/;/@/g; $newname =~ s/[ `'"!&*$;]/_/g; $newname =~ s/\$/_/g; $newname =~ s/[:{}|()<>]/-/g; $newname =~ s/^-/_/; $newname =~ s/\?/q/g; $newname =~ s/#/=/g; $newname =~ s/\\/_/g; justLowercase: $newname =~ tr/A-Z/a-z/; if ($putname) { print "$newname\n"; next; } $newname = $path . "/" . $newname; $_ = $path . "/" . $_; if ($newname ne $_) { print "$_ -> $newname\n"; if (-e $prefix . $newname) { print STDERR "$newname already exists; can't rename\n"; } else { if (rename($prefix . $_, $prefix . $newname)) { $_ = $newname; } else { print STDERR "Rename to $newname failed.\n"; } } } # Changes to file contents . . . $_ = $prefix . $_; if (-T $_ && !$cdrom) { if (system('uncrnl', $_)/256 == 0) { print "Uncrnl'ed $_\n"; } else { print STDERR "Uncrnl $_ failed.\n"; } } } --------------Boundary-00=_L7POY5N4J9GXWY9SX6KQ Content-Type: application/x-shellscript; name="uncrnl" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="uncrnl" #! /bin/tcsh -f # set echo # By Brian T. Schellenberger # probably pointless but I didn't know about fromdos or whatever the # standard tool is when I wrote it. if ("$1" =~ */*) then set plc = $1:h set file = $1:t cd $plc else set file = $1 endif mv $file }$file} tr < }$file} > $file -d '\r' --------------Boundary-00=_L7POY5N4J9GXWY9SX6KQ-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message