The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Lowercase to Uppercase ggovotsis AIX 7 10-16-2008 11:07 AM
make uppercase kirkm76 UNIX for Dummies Questions & Answers 4 05-29-2007 12:28 AM
How convert lowercase or uppercase Alex20 Shell Programming and Scripting 5 03-07-2005 07:07 AM
Converting to Uppercase dreams5617 Shell Programming and Scripting 3 11-12-2004 01:44 AM
uppercase to lowercase webex Shell Programming and Scripting 4 01-03-2002 02:15 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-22-2007
fedora fedora is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 94
only uppercase first character?

should be a simple question, I am trying to uppercase every first character in a word on the list.

abc
google
cnn
services

My first thought was sed 'y/^[a-z]/^[A-Z]/', but it changed all the characters, not just the first character.

any thoughts?
  #2 (permalink)  
Old 05-22-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Code:
## Following extract the first initial character only:
sed 's/\(.\).*/\1/' input_file > $$FirstChar

## Following extract from the second character on:
sed 's/.\(.*\)/\1/' input_file > $$OtherChars

## Following changes the first character to upper case:
tr '[a-z]' '[A-Z]' < $$FirstChar > $$UpperChar

## Following paste together the upper case character and
## the other characters:
paste -d'\0' $$UpperChar $$OtherChars

## Following removes temporary files:
rm -f $$*
  #3 (permalink)  
Old 05-22-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,553
if you have python here's an alternative:
Code:
# echo "astring"  | python -c "print raw_input().capitalize()"
Astring
  #4 (permalink)  
Old 05-22-2007
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,897
Code:
ex - infile<<!
%s/^./\u&/|x
!
  #5 (permalink)  
Old 05-23-2007
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 712
Hi.

Also in perl:
Code:
#!/bin/sh

# @(#) s1       Demonstrate quickie perl for uppercase first character.

FILE=${1-data1}

perl -wp -e '$_ = ucfirst' $FILE

exit 0
run on your sample in file data1 produces:
Code:
% ./s1
Abc
Google
Cnn
Services
cheers, drl
  #6 (permalink)  
Old 05-23-2007
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,236
A more general version for one or more words on a line:

Code:
awk '{ for ( i=1; i <= NF; i++) 
           {   sub(".", substr(toupper($i),1,1) , $i)  }  
            print }' file
use nawk/gawk/mawk as appropriate if awk doesn't work
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0