Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!pacbell.com!ucsd!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal L. Schwartz) Newsgroups: comp.unix.questions Subject: Re: need AWK help: lowercase, trim trailing spaces Keywords: awk Message-ID: <1991Apr21.180714.28672@iwarp.intel.com> Date: 21 Apr 91 18:07:14 GMT References: <1817@wjvax.UUCP> <1991Apr21.015014.18228@iwarp.intel.com> <1991Apr21.045226.16050@midway.uchicago.edu> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal L. Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 62 In-Reply-To: goer@ellis.uchicago.edu (Richard L. Goerwitz) In article <1991Apr21.045226.16050@midway.uchicago.edu>, goer@ellis (Richard L. Goerwitz) writes: | merlyn@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@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/