For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > September 2006 > Case change copy









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Case change copy
GeorgeM

2006-09-29, 7:01 pm

All:

Is there a Unix command that would allow me to copy(cp) a file and have
the target filename forced to uppercase?

ie myfile.dat --> MYFILE.DAT

or is there some Unix shell script code that can do this?

Thanks in advance,
George

jmcgill

2006-09-29, 7:01 pm

GeorgeM wrote:
> All:
>
> Is there a Unix command that would allow me to copy(cp) a file and have
> the target filename forced to uppercase?
>
> ie myfile.dat --> MYFILE.DAT
>
> or is there some Unix shell script code that can do this?


I'm sure there may be simpler ways to do it, but:



FILE=lower.txt
cp $FILE $(echo $FILE | tr 'a-z' 'A-Z')



Something in this direction may be useful for more elaborate things:

paste <(ls) <(ls |tr 'a-z' 'A-Z') |sed -e 's/^/cp /'

(That won't do the right thing for directories, I'm just trying to give
you a rough idea.)


There's probably a million ways to do this...
GeorgeM

2006-09-29, 7:01 pm

Thanks Jill, this works great for a file name alone..Actually my
variable includes the filename and full path. What would be a way to do
it with the directory path included?

Thanks,
George


jmcgill wrote:
> GeorgeM wrote:
>
> I'm sure there may be simpler ways to do it, but:
>
>
>
> FILE=lower.txt
> cp $FILE $(echo $FILE | tr 'a-z' 'A-Z')
>
>
>
> Something in this direction may be useful for more elaborate things:
>
> paste <(ls) <(ls |tr 'a-z' 'A-Z') |sed -e 's/^/cp /'
>
> (That won't do the right thing for directories, I'm just trying to give
> you a rough idea.)
>
>
> There's probably a million ways to do this...


GeorgeM

2006-09-29, 7:01 pm

Thanks Jill, this works great for a file name alone..Actually my
variable includes the filename and full path. What would be a way to do
it with the directory path included?

Thanks,
George


jmcgill wrote:
> GeorgeM wrote:
>
> I'm sure there may be simpler ways to do it, but:
>
>
>
> FILE=lower.txt
> cp $FILE $(echo $FILE | tr 'a-z' 'A-Z')
>
>
>
> Something in this direction may be useful for more elaborate things:
>
> paste <(ls) <(ls |tr 'a-z' 'A-Z') |sed -e 's/^/cp /'
>
> (That won't do the right thing for directories, I'm just trying to give
> you a rough idea.)
>
>
> There's probably a million ways to do this...


jmcgill

2006-09-29, 7:01 pm

GeorgeM wrote:
> [M]y variable includes the filename and full path. What would be a way to do
> it with the directory path included?


man basename
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com