The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Lowercase to Uppercase ggovotsis AIX 7 10-16-2008 11:07 AM
Log4j overwriting logs! ..sometimes... .Chris. UNIX for Dummies Questions & Answers 1 03-12-2008 10:46 AM
Need to change filenames in a particular directory from lowercase to UPPERCASE Duke_Lukem UNIX for Dummies Questions & Answers 7 01-07-2008 06:32 PM
How convert lowercase or uppercase Alex20 Shell Programming and Scripting 5 03-07-2005 07:07 AM
uppercase to lowercase webex Shell Programming and Scripting 4 01-03-2002 02:15 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-21-2008
lgd923 lgd923 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 1
UPPERCASE to lowercase with no overwriting?

Hey, I've just started learning shell script today.

How would I write a bash script file that changes file names from uppercase to lowercase in that directory, the program should warn the user and NOT overwrite the existing file if it's already in lowercase?

for example in a directory i have files called: hello1.txt HELLO2.txt
and after executing script it would print outsomething like : Not overwriting hello1.txt, and the file names become

hello1.txt hello2.txt

any help would be great
  #2 (permalink)  
Old 08-21-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,886

Code:
ls -1 | grep "^[A-Z]*\." | 
while read file; do
   newfile=`echo $file | tr '[A-Z]' '[a-z]'`
   if test -e "$newfile"; then
      echo >&2 $newfile exists, not overwriting
   else
      mv -- "$file" "$newfile"
   fi
done

I use grep here because I assume ALL the characters (before the period) must be capitals.
Closed Thread

Bookmarks

Tags
bash, lowercase, shell script, unix

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:32 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0