Solved

Lower to uppercase in Bourne shell

Posted on 2001-06-13
6
808 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running shell command from Access 3 75
iSeries DB2 Query 2 95
substring method in java 1 122
Capture logon name 13 73
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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