- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script-help
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2003 04:30 AM
03-10-2003 04:30 AM
I need to write a script which convert the lowercase letter in a filename to uppercase letters. For example I have a file called bts.a303 and I want to rename it to BTS.A303. I have to do that for 20 files at once in a directory. The problem is I know there is a function called toupper but I don't know how to use it in a shell script.
Regards,
ionut .
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2003 04:32 AM
03-10-2003 04:32 AM
Re: script-help
tr "[:lower:]" "[:upper:]"
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2003 04:33 AM
03-10-2003 04:33 AM
Re: script-help
See the man pages for 'tr'. You can do this:
# tr "[:lower:]" "[:upper:]" < infile > outfile
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2003 04:50 AM
03-10-2003 04:50 AM
SolutionYou need the shell typeset option
set -x
file=bts.a303
typeset -u fileu=$file
echo mv $file $fileu
output
+ file=bts.a303
+ typeset -u fileu=bts.a303
+ echo mv bts.a303 BTS.A303
mv bts.a303 BTS.A303
Steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2003 05:10 AM
03-10-2003 05:10 AM
Re: script-help
BTW, the 'toupper' function you are thinking of belongs to 'awk'. You could use it thusly to translate your lowercase to uppercase:
# echo "bts.a303"|awk '{print toupper($0)'}
Using 'tr':
# echo "bts.a303"|tr "[:lower:]" "[:upper:]"
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2003 05:22 AM
03-10-2003 05:22 AM
Re: script-help
Or you could use perl:
perl -e '{foreach $f (<*>){rename($f,uc $f)}}'
rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2003 05:24 AM
03-10-2003 05:24 AM
Re: script-help
a simple script solution:
#!/usr/bin/sh
# Dir. in which the files are
FILEDIR=
cd $FILEDIR
# list of the filenames to change
FILENAMES="bts.a303 file2"
for i in $FILENAMES
do
UPPER=$(echo $i|tr "[:lower:]" "[:upper:]")
echo "mv $i $UPPER"
#mv $i $UPPER
done
where you need to set FILEDIR to the dir., in which the files are.
FILENAMES should be a list of the file names you want to rename. If it looks sensible, then uncomment the #mv line.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2003 05:27 AM
03-10-2003 05:27 AM
Re: script-help
How's this:
# ll
total 0
-rw-rw-rw- 1 root sys 0 Mar 10 08:26 Hkwla.888
-rw-rw-rw- 1 root sys 0 Mar 10 08:26 JEKSI.888
-rw-rw-rw- 1 root sys 0 Mar 10 08:26 hywue.888
-rw-rw-rw- 1 root sys 0 Mar 10 08:26 jsjs.888
# ls -1 | awk '{system("mv " $1 " " toupper($1));}'
mv: JEKSI.888 and JEKSI.888 are identical
# ll
total 0
-rw-rw-rw- 1 root sys 0 Mar 10 08:26 HKWLA.888
-rw-rw-rw- 1 root sys 0 Mar 10 08:26 HYWUE.888
-rw-rw-rw- 1 root sys 0 Mar 10 08:26 JEKSI.888
-rw-rw-rw- 1 root sys 0 Mar 10 08:26 JSJS.888
#
If you are willing to ignore the fact that one file was already in upper case, then the above will work.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2003 05:44 AM
03-10-2003 05:44 AM
Re: script-help
case closed.
Harry: you took my breath away...
btw: it's working with $9, not $1, $1 are the permissions in ls -l output.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2003 05:46 AM
03-10-2003 05:46 AM
Re: script-help
a5:/tmp/tmp 112 > ll
total 8
581 drwxrwxrwx 2 merijn softwr 96 Mar 10 14:44 .
2 drwxrwxrwx 7 root root 4096 Mar 10 14:44 ..
575 -rw-rw-rw- 1 merijn softwr 5 Mar 10 14:44 Gff7.org
574 -rw-rw-rw- 1 merijn softwr 5 Mar 10 14:44 aGy.7
573 -rw-rw-rw- 1 merijn softwr 5 Mar 10 14:44 aaB
103 -rw-rw-rw- 1 merijn softwr 5 Mar 10 14:44 aaa
a5:/tmp/tmp 113 > perl -MFile::Copy -e'move$_,uc for<*>'
a5:/tmp/tmp 114 > ll
total 8
581 drwxrwxrwx 2 merijn softwr 96 Mar 10 14:44 .
2 drwxrwxrwx 7 root root 4096 Mar 10 14:44 ..
103 -rw-rw-rw- 1 merijn softwr 5 Mar 10 14:44 AAA
573 -rw-rw-rw- 1 merijn softwr 5 Mar 10 14:44 AAB
574 -rw-rw-rw- 1 merijn softwr 5 Mar 10 14:44 AGY.7
575 -rw-rw-rw- 1 merijn softwr 5 Mar 10 14:44 GFF7.ORG
a5:/tmp/tmp 115 >
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2003 05:46 AM
03-10-2003 05:46 AM
Re: script-help
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2003 05:52 AM
03-10-2003 05:52 AM
Re: script-help
The ls command doesn't actually need the "-1" switch if stdout is a pipe:
ls | awk '{print $1}'
is identical to:
ls -1 | awk '{print $1}'
rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2003 05:55 AM
03-10-2003 05:55 AM
Re: script-help
If you are going to leverage 'ls' and move your files, I'd consider filtering and processing *only* files:
# cd
# ls -l |awk '/^-/ {system("mv " $9 " "toupper($9))}'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2003 06:04 AM
03-10-2003 06:04 AM
Re: script-help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2003 06:19 AM
03-10-2003 06:19 AM
Re: script-help
-M means 'use a mudule'
if that fails, you're probably using perl4.x, which is quite old. I'm using 5.8.0 plus some extra patches.
You can check your version with 'perl -v' (short) or 'perl -V' (long), which should IMHO show at least 5.6.1 to be useful for /my/ examples
Check the location of your perl binary with 'which perl'. perl4 is located in /usr/contrib/bin. If perl5 is installed on your system, it can be found in either /opt/perl5 or /usr/local (the executable for both in bin/perl). If it is not, it is freely available from several sources (https://www.beepz.com/personal/merijn/ or http://www.cmve.net/~merijn/ or http://hpux.connect.org.uk/hppd/hpux/Languages/perl-5.8.0/ to name a few)
Now for the script:
perl -MFile::Copy -e'move$_,uc for<*>'
-MFile::Copy uses the File::Copy module that is included in the CORE distribution of Perl, and offers OS-independant copy/move commands
-e passes an expression to perl. The expression here is 'move$_,uc for<*>', which only parses OK in newer perls where the 'for' loop is allowed as a statement modifier, allowing to leave out the parenteses. Rewritten in C-like structure, that would read as
for (glob ("*")) {
move ($_, uc $_);
}
<*> is a shorthand for a list of all files, which is effectively fetched with perl's 'glob' function. Most base functions in perl have optional arguments that default to the global variable $_. 'uc' is the "uppercase" function. Parenteses are aften optional too, and spaces also, as long as leaving them out does not confuses the parser.
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2003 07:10 AM
03-10-2003 07:10 AM
Re: script-help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2003 07:51 AM
03-10-2003 07:51 AM