regular expression help

hello all.. I'm a bit new to this site.. and I hope to learn alot.. but I've been having a hard time figuring this out. I'm horrible with regular expressions.. so any help would be greatly appreciated.

I have a file with a list of names like this: LASTNAME, FIRSTNAME, MIDDLEINITIAL

how can I write a script to have the it: Firstname, Middleinitial, Lastname ?

I have around 30ish names. The first letter needs to be capitalized and the rest lowercase.. I've been having a horrible time trying to figure this out.. I would really appreciate some help with this.

According to our rules:
(6) Do not post classroom or homework problems.

it's not really a classwork or homework problem..

it's like one that we have to do.. but it's not it.. like I said, I'm horrible at reg ex's.. and any hints or anything would really help

I would not use a regular expression at all for this problem. I would just use ksh. It can easily read 3 words from a line and write them out in a different order. It can also split off a leading character from a word and there are plenty of example of that on this site. Look at ksh's "typeset -l" and "typeset -u" to automaticly enforce one case or another. At most, this looks like a 20 line ksh script.

thanks.. that looks like it's alot easier than what I was trying to do.

I was looking at using the awk statement, finding someway to copy the first char of the parameter then use the [[:lower:]] command

ok. Try this as,

awk -F , '{ la=substr($1,1,2);lb=substr($1,3); fa=substr($2,1,2);fb=substr($2,3); ma=substr($3,1,2);mb=substr($3,3); print fa""tolower(fb)", "ma""tolower(mb)", "la""tolower(lb) }' <filename>

For Example as,

# echo " LASTNAME, FIRSTNAME, MIDDLEINITIAL" | awk -F , '{ la=substr($1,1,2);lb=substr($1,3); fa=substr($2,1,2);fb=substr($2,3); ma=substr($3,1,2);mb=substr($3,3); print fa""tolower(fb)", "ma""tolower(mb)", "la""tolower(lb) }'
Firstname, Middleinitial, Lastname

HTH.