Converting file names to upper case | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Converting file names to upper case

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-10-2006
Sabari Nath S Sabari Nath S is offline
Registered User
 
Join Date: Jul 2005
Last Activity: 3 June 2011, 5:49 PM EDT
Location: Chennai
Posts: 53
Thanks: 0
Thanked 1 Time in 1 Post
Converting file names to upper case

Hi all,

I am trying to rename all my files in a directory to their upper case counterparts .... I want to do this in a single command and not through shell script ... I started off thinking it wud be simple but got stuck up in middle since tr does not work the way i thought ...

This is what i tried ...

ls | xargs -l1 -t -i mv {} `echo {} | tr '[a-z]' '[A-Z]'`

Here tr does not seem to do any work and just returns the file name as such .. So in effect i am renaming a file to that name itself ...

mv try.cc try.cc
mv: try.cc and try.cc are identical
mv typescript typescript
mv: typescript and typescript are identical

Why is this happening ?? And can anyone suggest me a solution
Sponsored Links
    #2  
Old 01-10-2006
linuxpenguin's Avatar
linuxpenguin linuxpenguin is offline Forum Advisor  
Registered User
 
Join Date: May 2002
Last Activity: 28 March 2014, 4:09 PM EDT
Location: India
Posts: 350
Thanks: 0
Thanked 5 Times in 5 Posts
for i in *
do
mv $i `echo $i|awk '{print toupper($0)}'`
done

now i dunno if you can consider this as a one line command, but i think it has to be, coz you cant execute each of the above line separately by itself to get your result
Sponsored Links
    #3  
Old 01-10-2006
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
 
Join Date: Dec 2003
Last Activity: 13 May 2013, 9:02 AM EDT
Location: Melbourne, Australia
Posts: 2,185
Thanks: 3
Thanked 24 Times in 23 Posts
Not one line, but efficient with ksh builtins...

Code:
# ls
file_1  file_2  file_3
# ls | while read filename; do
>    typeset -u uppercase
>    uppercase=${filename}
>    mv ${filename} ${uppercase}
> done
# ls
FILE_1  FILE_2  FILE_3

Cheers
ZB
    #4  
Old 01-12-2006
Sabari Nath S Sabari Nath S is offline
Registered User
 
Join Date: Jul 2005
Last Activity: 3 June 2011, 5:49 PM EDT
Location: Chennai
Posts: 53
Thanks: 0
Thanked 1 Time in 1 Post
Here my list of files to be renamed comes from some other command like find or something ... so i wud need to use xargs for doing this Also i want to do rename interactively ....

even when i put this awk part in xargs as below :

ls | xargs -l1 -t -i echo {} `echo {}|awk '{print toupper($0)}'`

awk doesnt work as tr in my first post...

where as here wc works

ls | xargs -l1 -t -i echo {} `echo {}|wc`

Can anyone tell me the reason why this happens ???
Sponsored Links
    #5  
Old 01-12-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 20 December 2014, 10:46 PM EST
Location: Ashburn, Virginia
Posts: 9,930
Thanks: 64
Thanked 440 Times in 261 Posts
Quote:
Originally Posted by Sabari Nath S
ls | xargs -l1 -t -i echo {} `echo {}|awk '{print toupper($0)}'`
`echo {}|wc`

Can anyone tell me the reason why this happens ???
Neither command works for me. You must be testing in a directory with only a few two character filenames if you think the second one works. Create a few longer filenames. The shell sees `echo {} | wc`; so it runs that pipeline and it gets "{} 1 1 3" which it replaces in your command. So then you run:
ls | xargs -l1 -t -i echo {} {} 1 1 3
Sponsored Links
    #6  
Old 01-12-2006
linuxpenguin's Avatar
linuxpenguin linuxpenguin is offline Forum Advisor  
Registered User
 
Join Date: May 2002
Last Activity: 28 March 2014, 4:09 PM EDT
Location: India
Posts: 350
Thanks: 0
Thanked 5 Times in 5 Posts
hmm, well if it is output of command find, you can pipe it to a for or while loop as follows, instead of using the xargs.

=>find . | while read a
do
mv "$a" `echo "$a"|awk '{print toupper($a)}'`
done
mv: `.' and `./.' are the same file

if this still doesnt fit in your scenario, tell us what is that makes you so mandatory that you just cant do without using xargs?
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
converting to lower case or upper case vivek d r Shell Programming and Scripting 6 12-01-2011 02:16 AM
convert file names to upper case using tr command in Unix a1_win Shell Programming and Scripting 3 07-16-2009 03:56 AM
Perl - converting selected characters to upper/lower case doubleminus UNIX for Dummies Questions & Answers 2 05-19-2008 02:13 AM
lower case to upper case string conversion in shell script dchalavadi UNIX for Dummies Questions & Answers 3 05-29-2002 01:07 AM
variables use upper case? sed : output to the same file? gusla UNIX for Dummies Questions & Answers 1 04-05-2002 12:24 AM



All times are GMT -4. The time now is 02:38 PM.