From owner-freebsd-questions@FreeBSD.ORG Thu Mar 27 01:21:19 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3A3B737B401 for ; Thu, 27 Mar 2003 01:21:19 -0800 (PST) Received: from sferics.mongueurs.net (sferics.mongueurs.net [81.80.147.197]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7A8AB43FA3 for ; Thu, 27 Mar 2003 01:21:18 -0800 (PST) (envelope-from david@landgren.net) Received: from landgren.net (81-80-147-206.bpinet.com [81.80.147.206]) by sferics.mongueurs.net (Postfix) with ESMTP id 3BAB0ADE8 for ; Thu, 27 Mar 2003 10:21:13 +0100 (CET) Message-ID: <3E82CA87.6040804@landgren.net> Date: Thu, 27 Mar 2003 10:55:19 +0100 From: David Landgren User-Agent: Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: freebsd-questions@FreeBSD.ORG References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, hits=-26.5 required=5.0 tests=AWL,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_MOZILLA_UA autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) Subject: Re: perl help X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Mar 2003 09:21:22 -0000 Kenzo wrote: [resend. I sent this yesterday but it doesn't appear to have turned up on the list.] > I don't know how to write anything in perl and will eventually learn it. > but I was wondering if anyone would help write a quick perl script for > me. You really ought to try a different forum. Perl Monks (http://www.perlmonks.org/) springs to mind. > Basically I want the script to look thru a file for certain words and > cound > how many times it finds the word that comes after. > I have a log file that keeps track of E-mail attachments being send and > received, and I want to be able to do a count of certain attachments. > for example. say I see alot of "big this", "big that" and "big nothing" > I want to be able to see how many times the word that comes after big > appears in the log file. > so the output would be like this. > this 5 > that 10 > nothing 20 Well that's pretty easy... #! /usr/bin/perl -w use strict; my $target = shift or die "No target word given on command line"; my $prev; my %follow; while( <> ) { chomp; # break the line into elements my @word = split; # deal with the leftover of the previous line ++$follow{$word[0]} if $prev and $prev eq $target; # walk down the line $word[$_] eq $target and ++$follow{$word[$_+1]} for 0 .. @word - 2; # carry over the last word to the next line $prev = $word[-1]; } # print out the results print "$_\t$follow{$_}\n" for sort keys %follow; > I hope this is not too confusing. I might say the same of my script :) > thanks. You're welcome. David