Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!mailrus!purdue!bu-cs!oliveb!mipos3!omepd!merlyn From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.unix.questions Subject: Re: Stupid awk question Message-ID: <5042@omepd.UUCP> Date: 12 Oct 89 04:21:27 GMT References: <15023@bloom-beacon.MIT.EDU> Sender: news@omepd.UUCP Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Distribution: comp Organization: Stonehenge; netaccess via Intel, Hillsboro, Oregon, USA Lines: 34 In article <15023@bloom-beacon.MIT.EDU>, jik@athena (Jonathan I. Kamens) writes: | In article dmaustin@vivid.sun.com | (Darren Austin) writes: | >(current == $2) {print > current".summary"} | >(current != $2) {close(current".summary");current=$2;print > current".summary";} | > [fails] | [describes why it fails] | May I suggest either nawk (I don't know where/under what conditions | that's available), or gawk (available for nothing whereever fine GNU | products are distributed)? Or do it in Perl (of course)... #!/usr/bin/perl while (<>) { ($where) = (/^\s*\S+\s+(\S+)/); if ($oldwhere ne $where) { open(WHERE,">>$where.summary") || die "Cannot open $where.summary ($!)"; } print WHERE $_; } close(WHERE); (Perl users may note that the open will automatically close the previous open.) Just another Perl hacker, -- /== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\ | on contract to Intel's iWarp project, Hillsboro, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn | \== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/