Stupid awk question
Randal Schwartz
merlyn at iwarp.intel.com
Thu Oct 12 14:21:27 AEST 1989
In article <15023 at bloom-beacon.MIT.EDU>, jik at athena (Jonathan I. Kamens) writes:
| In article <DMAUSTIN.89Oct10145918 at vivid.sun.com> dmaustin at 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 at iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn |
\== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/
More information about the Comp.unix.questions
mailing list