home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!nwnexus!Celestial.COM!bill
- From: bill@Celestial.COM (Bill Campbell)
- Subject: Re: need script to rename uppercase filenames
- Organization: Celestial Software, Mercer Island, WA
- Date: Thu, 03 Sep 1992 15:12:45 GMT
- Message-ID: <1992Sep03.151245.11128@Celestial.COM>
- References: <699@svcs1.UUCP>
- Keywords: script,tar,msdos
- Lines: 44
-
- In <699@svcs1.UUCP> slix@svcs1.UUCP (Bill Miller) writes:
-
- >Hi, everyone.
-
- >I'm fairly new to unix, and I need a script or procedure to do the following:
- >
- >I have some source code in DOS (many separate files) that I tarred under
- >DOS and untarred under 386BSD. The big problem is that all the files
- >came through in UPPERCASE and I need a script to mv (rename) them all
- >to lowercase quickly.
- >
- >Since they're in DOS text format, I realize I also need to strip the
- >extra carriage returns on each line. I've been successful in doing this
- >with:
- >
- > cat (file) | tr -d '\015' > (newfile)
- >
- >It would be nice to combine both of these so that I could rename the
- >files to uppercase and strip the extra newlines all in one fell swoop
- >instead of doing it one file at a time.
-
- A simple perl solution (needs more error checking):
-
- for $dos ( @ARGV ) {
- ( $unix = $dos ) =~ tr/A-Z/a-z/; # convert to lower case
- if ( -f $unix ) {
- print STDERR "Cannot convert $dos -- $unix exists\n";
- next;
- }
- open(DOS, $dos);
- open(UNIX, "> $unix");
- while (<DOS>) {
- s/\s+$//; # strip all trailing whitespace including ^M
- print UNIX;
- }
- close(DOS);
- unlink($dos); # remove old dos file
- close(UNIX);
- }
- --
- INTERNET: bill@Celestial.COM Bill Campbell; Celestial Software
- UUCP: ...!thebes!camco!bill 6641 East Mercer Way
- uunet!camco!bill Mercer Island, WA 98040; (206) 947-5591
- SPEED COSTS MONEY -- HOW FAST DO YOU WANT TO GO?
-