Solved

Lower to uppercase in Bourne shell

Posted on 2001-06-13
6
803 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:stibo
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

12 Experts available now in Live!

Get 1:1 Help Now