I mumbled,

> Ok, I'm tired of banging my head against this one.  I know there must be
> a simple perl, sed or tr solution, but I can't seem to find it.  I'm
> cleaning up some extracted data and the one annoying thing I have left
> is a single quote followed by a capital letter, which I want to change
> to lowercase like so:
> 
> Can'T -->  Can't
> Santa'S --> Santa's

Geoff Thurman <[EMAIL PROTECTED]> suggested:

> In perl, how about

> $_ = "Can'T eat shan'T eat Jane'S cooking.";
> s/'T /'t /g;
> s/'S /'s /g;
> print $_;

> Assuming it's only T and S.

I wish it were only T & S.  I'm working with a text file that has
180,000+ lines in it and the problem runs the gamut from A-Z.

Tomas Johansson <[EMAIL PROTECTED]> thought:

> Yes, or if you have an array of strings, and want to replace all
> capital letters in all strings, maybe this could be a solution:

> sub toLower
> {
>  my @parms = @_;
>  for (@parms) { tr/A-Z/a-Z/ }
>  return wantarray ? @parms : $parms[0];
>}

> @result = toLower(@array);


Not a bad idea either but I don't want to disturb the other capital
letters.

Matthew Melvin <[EMAIL PROTECTED]> turned in the "winning"
answer:

> How 'bout something like...

> $ cat in | perl -p -e "s/(\'[A-Z])/lc(\$1)/e"

I wound up with:

$ perl -p -e "s/(\'[A-Z])/lc(\$1)/e" <infile >outfile

I *knew* () / $1 substitution had to be in there somewhere, I just
couldn't figure it out.  I'm attempting to learn Perl, but at the moment
most of my work has been in manipulating MySQL databases.  I haven't
done much "text processing" yet.

Thanks for the help!

-Eric


-- 

Eric Sisler <[EMAIL PROTECTED]>
Library Applications Specialist
Westminster Public Library
Westminster, CO USA

Linux - Don't fear the Penguin.
Want to know what we use Linux for?
Visit http://gromit.westminster.lib.co.us/linux



-- 
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]
https://www.redhat.com/mailman/listinfo/redhat-list

Reply via email to