Solved

Lower to uppercase in Bourne shell

Posted on 2001-06-13
6
805 Views
Last Modified: 2013-12-26
Hi


In Bourne Shell I want in a script to be able to modify a string from lowercase to uppercase e.g. "test1" to "Test1".
Does any of you know which command I have to use and how to use it with pipes (e.g. echo test1 | <command> ) ??
Btw. It has to run under Solaris 2.x

Thanks!

Soren Larsen
0
Comment
Question by:stibo
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:marecs
ID: 6185581
If you want to convert all characters from lc to uc then simply do
echo test1 |tr 'a-z' 'A-Z'

From your example it looks like you only want to uc the first letter. Then this will work

echo test1 | ( dd ibs=1 count=1 2>/dev/null | tr 'a-z' 'A-Z' ; cat )
under bash and sh

Maybe somebody else has a simpler solution.

Cheers
0
 

Author Comment

by:stibo
ID: 6186405
Thanks Marecs

It works. But as you self point out, I also would like to know if there is a simpler solution.

Regards.
0
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 6186827
original_name=test1

all_but_first_char="${original_name#?}"
typeset -u upper_first_char="${original_name%$all_but_first_char}"
new_name="$upper_first_char$all_but_first_char"

print "$new_name"
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:stibo
ID: 6187858
Hi

Thanks for your answers, but I have not got the right answer yet, because:
Marecs, I can't get the "tr" command to work in Solaris 8 but it work alright in Solaris 2.6 ??!? When I run the "echo test1 |tr 'a-z' 'A-Z'" in sh, I get only "test1" as a result - no change in the output :-(

Chris: I want to do it in Bourne shell (sh). I guess you use perl ??

Thanks so far...
0
 
LVL 14

Accepted Solution

by:
chris_calabrese earned 100 total points
ID: 6187872
o The 'tr' bit doesn't work in Solaris 8 because it's using the stricter POSIX codings where a-z isn't a concept.   The correct tr command on Solaris 8 would be
  tr  '[:upper:]' '[:lower:]'

o That's POSIX shell and it works with /usr/bin/sh on Solaris 7.  Should work on 2.6 and 8 just fine too.
0
 

Author Comment

by:stibo
ID: 6188026
It work fine now. :-))

The following works:
echo test1 | ( dd ibs=1 count=1 2>/dev/null | tr '[:lower:]' '[:upper:]'; cat )

Result: Test1
That's what I was looking for.

Thanks all for your answers !!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now