Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Lower to uppercase in Bourne shell

Posted on 2001-06-13
6
Medium Priority
?
819 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 300 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

688 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