Solved

Lower to uppercase in Bourne shell

Posted on 2001-06-13
6
809 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

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.

820 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