Following a link that recently came up on the golf mailing list, I ran across this problem, which I thought was ripe for golfing. I thought their input format was ugly, so instead of taking the words to be ignored on standard input, they are passed as command-line arguments (this also complicates the golfing a bit). An example of proper behavior is:
% perl kwic.pl a an the an ostrich a big bird the an bird ^D a BIG bird a big BIRD the an BIRD an OSTRICH %
My best so far is an 85:
$i{$x}=1while$x=pop;s/\w+/$i{$&}or$k{$&}.="$`\U$&\E$'"/egwhile<>;print +@k{sort keys%k}
Then I thought "as an excercise, why not do this in Ruby?" Which yielded this 142:
p={} i={} ARGV.each{|x|i[x]=1}.clear while l=gets;l.gsub(/\S+/){|s|p[s]=''if !p[s];p[s]<<$`+$&.upcase+$'if +!i[s]}end p.sort.each{|x,y|print y}
/s

Update:MeowChow has pointed out Key Word In Context system (golf, anyone)?, which is suspiciously similar, though not identical.

Replies are listed 'Best First'.
(MeowChow) Re: (golf + ruby-golf) keyword in context
by MeowChow (Vicar) on May 13, 2002 at 20:21 UTC
    You may find this interesting.
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print