I am new to using regex expressions, and am having difficulty with the syntax creating workable regexs.

I hope this not too much for one post. But I have been working on this for a while and can't get beyond the basics. Any suggestions would be appreciated.

I am using BSD SED on a Mac 10.3.9

My first project:

Source Text:

D08/14/2009NN/APBAJA FISH TACOST-8.45^I want to convert the text after the P - BAJA FISH TACOS - to title case.

I have focused on Sed as my tool of choice, but wonder if Perl may be a better choice.

I want to write a script to covert selected pieces of text in a file from all CAPS to Title Case. Ultimately, will want to use lookbehind to capture text after delimitating P. Which would I believe the regex would be:(?<=^P).*

I can't seem to get started with SED. Before I show you the potential solutions, I would like to ask some basic questions to enhance my regex knowledge.

To build my knowledge of regex use I tried a few basic regex building blocks.

Want to do a simple replace, but only if text is at beginning of word.

I want to start with these "building block" before moving on to my difficult task.

Any suggestions on why the above doesn't work would be greatly appreciated. I am going to add my follow on question on potential solutions to my problem, but want to understand the simple before diving in to the deep end, so to speak.

CONVERT CASE PROJECTOn to the problem at hand. (I am eliminating the lookbehind to simplify.)I found these on the bashscripts.org board & a link from a post discussing these.

Potential Solution #1:Sample Text:

THE SOMEWHERE STORELOCAL FOODSA GOOD PLACE TO BE

Title Case

Code:

sed 's/\(\<.\)\.*/\u\1/g' filename;

This is how I break down the 1st sed:

First () group - hold for backreference - $1\<.\> first character of each word\.* rest of word\u\1 convert first backreference -$1- to lower case.

Am I reading this correctly?

First can someone explain what I am doing wrong in Test #1?

Second, if not too much trouble, can someone guide me through my CONVERT CASE PROJECT? Would like to know; Is sed the proper tool? Does \u work as my SED reference indicates? If so, some feed back on my solution and explanation on my regex.

Again, I know this is a lot, but I have been working on this for a bit, and can't get beyond these basics, particularly in my basic effort Test #1.

Who is online

Users browsing this forum: No registered users and 7 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum