[PLUG] substitution question...

Eitan Tsur eitan.tsur at gmail.com
Tue Dec 9 19:52:04 UTC 2008


Wow...  Well all I really need is something that matches
"[apostrophe][letter][space]" and lowercases that letter in a string.  I
assume this can be done with sed or some other tool.  I'll tack it on to the
end of what I have so far, which does most of what I need already.

On Tue, Dec 9, 2008 at 11:20 AM, Fred James <fredjame at fredjame.cnc.net>wrote:

> Eitan Tsur wrote:
> > Ok, so here's a few examples... (from my music collection)
> >
> > Guns N' Roses
> > FAT FREDDY'S DROP
> > black_rebel_motorcycle_club
> >
> > The end results SHOULD be like so:
> > Guns N' Roses
> > Fat Freddy's Drop (note the 's is not capitalized)
> > Black Rebel Motorcycle Club (underscores converted to spaces)
> >
> Eitan Tsur
> Oops - I made an incorrect assumption ... assuming that the file name
> would have underscores instead of spaces (as in the
> "black_rebel_motorcycle_club" example) this would work (see below) ...
> but it won't work with spaces (i.e., "FAT FREDDY'S DROP")
> But you could use 'ls -1' to make a text file of names, (one name per
> line/record) and then feed those into the loop one line at a time - does
> that help?
> Regards
> Fred James
>
> #! /bin/bash
> #       naming.sh
> #       Usage: ./naming.sh directorypath
> Dir=$1
> for oldName in `ls -1 $Dir`
> do
>        echo "old name ${oldName}"
>        tempName=`echo ${oldName} | gawk -F\_ '{
>                for (i = 1;i < NF;i++) {
>                        if (length($i) > 1) {
>                                printf("%s", toupper(substr($i,1,1)))
>                                printf("%s_",substr($i,2))
>                        } else {
>                                printf("%s_", toupper($i))
>                        }
>                }
>                if (length($i) > 1) {
>                        printf("%s", toupper(substr($i,1,1)))
>                        printf("%s",substr($i,2))
>                } else {
>                        printf("%s", toupper($i))
>                }
>        }'`
>        tempName=`echo ${tempName} | sed -e 's/_/ /g'`
>        newName=`echo ${tempName} | sed -e 's/ /\ /g'`
>        echo "->$oldName<-"
>        echo "->$newName<-"
> done
> exit 0
>
> _______________________________________________
> PLUG mailing list
> PLUG at lists.pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug
>



More information about the PLUG mailing list