Perl - Title Case after apostrophe


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl - Title Case after apostrophe
# 1  
Old 02-14-2010
Perl - Title Case after apostrophe

I've got:

$string =~ s/(\w+)/\u\L$1/g;

Which capitalizes each word in the string. The problem is if I have a string with an apostrophe the first letter after it gets capitalized as well.

So Bob's becomes Bob'S.

Thanks for any quick fixes!
# 2  
Old 02-14-2010
Hello,

Try this
Code:
gaurav@localhost:~$ perl -wlp -e 's/(\S+)/\u\L$1/g;' <<< "Bob's gone to market"
Bob's Gone To Market
gaurav@localhost:~$

Regards,
Gaurav.
# 3  
Old 02-14-2010
Ah.... \S = any non-whitespace character!

Super... thank you very kindly!
# 4  
Old 02-14-2010
Quote:
Originally Posted by gaurav1086
Code:
gaurav@localhost:~$ perl -wlp -e 's/(\S+)/\u\L$1/g;' <<< "Bob's gone to market"
Bob's Gone To Market

Regards,
Gaurav.
Only \u is enough...

Code:
echo "Bob's gone to market" | perl -wlp -e 's/(\S+)/\u$1/g;'

# 5  
Old 02-14-2010
Quote:
Originally Posted by thegeek
Only \u is enough...

Code:
echo "Bob's gone to market" | perl -wlp -e 's/(\S+)/\u$1/g;'


Hello,

No only \u is not enough as we dont want something like this. ->

Code:
gaurav@localhost:~$ perl -wlp -e 's/(\S+)/\u$1/g;' <<< "BOb's goNe tO maRkEt"
BOb's GoNe TO MaRkEt
gaurav@localhost:~$

Regards,
Gaurav.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert text between exact matching patterns to Title case

Hi Folks, I have a large text file with multiple similar patterns on each line like: blank">PATTERN1 some word PATTERN2 title=">PATTERN1 some word PATTERN2 blank">PATTERN1 another word PATTERN2 title=">PATTERN1 another word PATTERN2 blank">PATTERN1 one more time PATTERN2 title=">PATTERN1... (10 Replies)
Discussion started by: martinsmith
10 Replies

2. UNIX for Advanced & Expert Users

Shell script to convert words to Title case

Hi :) I have a .txt file with thousands of words. I was wondering if i could use a simple sed or awk command to convert / replace all words in the text file to Title Case format ? Example: from: this is line one this is line two this is line three to desired output: This Is Line... (8 Replies)
Discussion started by: martinsmith
8 Replies

3. Shell Programming and Scripting

Perl title help

my codeothers (1 Reply)
Discussion started by: sauravrout
1 Replies

4. Shell Programming and Scripting

Making case insensitive perl statement

cat > tble blah blah blah sdfsdf dsdf sdf .d.f ..df .. sdf.. create table NextID ( id int auto_increment, zoneID int, entityName varchar(64), nextID int, lastModified TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, primary... (6 Replies)
Discussion started by: vivek d r
6 Replies

5. Shell Programming and Scripting

Replace apostrophe with backslash apostrophe

I'm coding using BASH and have a requirement to replace apostrophes with backslash apostrophes. For example below: I am here 'in my room' ok Would be changed to: I am here /'in my room/' ok The original text is coming from a field in a MySql database and is being used by another process that... (5 Replies)
Discussion started by: dbjock
5 Replies

6. Shell Programming and Scripting

PERL - traverse sub directories and get test case results

Hello, I need help in creating a PERL script for parsing test result files to get the results (pass or fail). Each test case execution generates a directory with few files among which we are interested in .result file. Lets say Testing is home directory. If i executed 2 test cases. It will... (4 Replies)
Discussion started by: ravi.videla
4 Replies

7. Shell Programming and Scripting

Perl index function ignore case

Hi, Is there any way of ignoring case in Perl's index function? Thanks. (2 Replies)
Discussion started by: King Nothing
2 Replies

8. Shell Programming and Scripting

Shell/Perl script to convert to Capitalize case

I need a shell script which will convert the given string within a <title> tag to Capitalize case. E.g "<title>hi man: check this out</title>" to "<title>Hi Man: Check This Out</title>" (11 Replies)
Discussion started by: parshant_bvcoe
11 Replies

9. UNIX for Dummies Questions & Answers

Perl - converting selected characters to upper/lower case

Using STDIN, how can I use perl to take an input string, with all lower case letters in the first five characters, and convert them to uppercase... then take all uppercase letters in the second five characters and convert them to lowercase. Example: MichaelSmith to michaELSMIth Thank you! (2 Replies)
Discussion started by: doubleminus
2 Replies

10. UNIX for Advanced & Expert Users

Shell script to convert to Title case

I need a shell script which will convert the given string to Title case. E.g "hi man" to "Hi man" (5 Replies)
Discussion started by: SankarV
5 Replies
Login or Register to Ask a Question