need AWK help: lowercase, trim trailing spaces

Randal L. Schwartz merlyn at iwarp.intel.com
Mon Apr 22 04:07:14 AEST 1991


In article <1991Apr21.045226.16050 at midway.uchicago.edu>, goer at ellis (Richard L. Goerwitz) writes:
| merlyn at iwarp.intel.com (Randal L. Schwartz) writes:
| >
| >while (<>) {
| >	s/([A-Z]{3,})/\u\L$1$2/g;
| >	($name,$address1,$address2,$city,$zip) = unpack("A10A19A17A24A*",$_);
| >	print "$name\n";
| >	print "$address1\n";
| >	print "$address2\n" if $address2;
| >	print "$city $zip\n";
| >	print "\n";
| >}
| >
| >Works just fine on your test data.
| 
| No, no!  The gentleman said quite plainly that he wanted his data to
| look like this:
| 
| Company1
| 28 Fulling
| P O Box 3608
| Harrisburg PA 17105
| 
| Company2
| 500 Elm
| Milwaukee WI 53122
| 
| Company3
| 13500 Central
| P O Box 655303
| Dallas TX 75265-5303
| 
| Did you actually try running your perl code?

Yes.  That's exactly what came out.  If it didn't come out on *your*
Perl, you have an old Perl.  (I used the new \u\L operators, if that's
what you're objecting to.)

I did make a silly typo in the first one.  The line:

	s/([A-Z]{3,})/\u\L$1$2/g;

should read:

	s/([A-Z]{3,})/\u\L$1/g;

The $2 was a leftover from doing it as two partial expressions, but
then I realized I didn't need to do that.  But the code worked in
either case, which is why I didn't catch it. :-)

This line finds 3 or more letters, and then lowercases all letters
after the first.  That was part of the spec.

(I hope I'm responding to your criticism.  It wasn't very specific.
But believe me, the code *does* work as requested.)

print "Just another Perl hacker,"
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn at iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/



More information about the Comp.unix.questions mailing list