Lesson 3





元のkwic1.pl
----------     ----------
$string = '\bjust\b';
$/ = "";

while(<>){
   s/ *\n */ /g;

   while(/$string/ig){

      $count++;

      $key  =  $&;
      $pre  =  substr ($`, -25);
      $post =  substr ($', 0, 25);

      $file =  $ARGV;
      $file =~ s#.*/([^/]+)$#$1#;

      printf "%5d | %s | %25s|%s|%-25.25s\n",
              $count, $file, $pre, $key, $post;
   }
}
exit;
----------     ----------




練習問題A


1.  kwic1.pl$string の値を変え,いろいろな文字列を検索しなさい。

 > perl script/kwic1-111.pl voa/*
          ※ kwic1-111.pl では $string = '\bmore\b'

    1 | 2-257701.txt | aland last September and |more| recently at the Middle E
    2 | 2-257702.txt |             The Crown is |more| than a piece of exhibiti
    3 | 2-257703.txt | it.  A packed stadium of |more| than 93-thousand fans tu
    4 | 2-257703.txt |  could have scored a few |more| times so we wouldn't hav
    5 | 2-257705.txt |                   INTRO: |More| than 70 Tamil Tiger rebe
    6 | 2-257706.txt | war.  Bill Gasperini has |more| from Moscow.            
    7 | 2-257713.txt | -O-A's David Gollust has |more| from the White House.   
    8 | 2-257716.txt | es and local services in |more| remote parts of the coun
    9 | 2-257717.txt | ople -- and perhaps many |more| -- were killed in clashe
   10 | 2-257719.txt | ew Year by calling for a |more| democratic Hong Kong. In
   11 | 2-257719.txt | arty have all called for |more| democratization in Hong
   12 | 2-257721.txt | ed 14-people and injured |more| than 30 others at a mark
   13 | 2-257721.txt | ts since hijackers freed |more| than 150-hostages New Ye
   14 | 2-257721.txt | a says the hijackers had |more| guns after they landed i
   15 | 2-257721.txt |  the aircraft there were |more| arms in the aircraft.   
   16 | 2-257725.txt | apture the capital began |more| than a week ago, federal
   17 | 2-257725.txt | his way.  He said unless |more| army troops are committe
   18 | 2-257726.txt | etween both countries in |more| than 50-years of conflic
   19 | 2-257727.txt | S Coast Guard is sending |more| than 400 boat people bac
   20 | 2-257729.txt | l pave the way towards a |more| democratic future for th
......

   60 | 2-257820.txt | aptured by Israel in war |more| than 30 years ago.  The
   61 | 2-257821.txt | s also time for broader, |more| philosophical questions.
   62 | 2-257824.txt | by India in exchange for |more| than 150 hostages aboard
   63 | 2-257824.txt |                      For |more| than a decade, India has
   64 | 2-257827.txt | ources say eight million |more| people in China are loya
   65 | 2-257827.txt |  Catholics are generally |more| loyal to the Pope. (sign
   66 | 2-257829.txt | to eradicate polio began |more| than a decade ago. That
   67 | 2-257835.txt | manders are admitting to |more| casualties in the Chechn
   68 | 2-257835.txt | e capital. Officials say |more| than 100-rebels died in
   69 | 2-257835.txt | an casualty figures show |more| than 450-troops killed a
   70 | 2-257835.txt | an 450-troops killed and |more| than 15- hundred injured
   71 | 2-257843.txt | osition election rally.  |More| than two dozen people we
   72 | 2-257846.txt |       He says there were |more| days last year in which
   73 | 2-257846.txt |  They say there has been |more| strict enforcement of la
   74 | 2-257849.txt | ps - just, as he put it, |more| "chugging along" (slow p
   75 | 2-257849.txt | st means we'd like to do |more|.  So we're trying to acc
   76 | 2-257849.txt | e negotiations stand, so |more| time can be spent on pur
   77 | 2-257849.txt | i/Syrian relations after |more| than 50 years of war and




2. 出力結果を sort を使い,フィールドを指定してソートしなさい。

 > perl script/kwic1-111.pl voa/* | sort -f -t "|" -k 4
......

   61 | 2-257821.txt | s also time for broader, |more| philosophical questions.
    1 | 2-257701.txt | aland last September and |more| recently at the Middle E
    8 | 2-257716.txt | es and local services in |more| remote parts of the coun
   39 | 2-257786.txt | es with the discovery of |more| stowaways on cargo ships
   73 | 2-257846.txt |  They say there has been |more| strict enforcement of la
   33 | 2-257773.txt | , ballots will go out to |more| than 10-thousand voting
   68 | 2-257835.txt | e capital. Officials say |more| than 100-rebels died in
   70 | 2-257835.txt | an 450-troops killed and |more| than 15- hundred injured
   44 | 2-257793.txt |                          |More| than 15-hundred people a
   62 | 2-257824.txt | by India in exchange for |more| than 150 hostages aboard
   13 | 2-257721.txt | ts since hijackers freed |more| than 150-hostages New Ye
   31 | 2-257752.txt | Last year, Beijing spent |more| than 24 billion dollars
   41 | 2-257786.txt | he  "California Jupiter" |more| than 250-thousand dollar
   12 | 2-257721.txt | ed 14-people and injured |more| than 30 others at a mark
   55 | 2-257815.txt | aptured by Israel in war |more| than 30 years ago.  Sinc
   60 | 2-257820.txt | aptured by Israel in war |more| than 30 years ago.  The
   48 | 2-257801.txt | ord, Israel has released |more| than 380 Palestinian and
   51 | 2-257807.txt | ord, Israel has released |more| than 380 Palestinian and
   19 | 2-257727.txt | S Coast Guard is sending |more| than 400 boat people bac
   69 | 2-257835.txt | an casualty figures show |more| than 450-troops killed a
   23 | 2-257737.txt | etween both countries in |more| than 50 years of conflic
   59 | 2-257820.txt | malizing relations after |more| than 50 years of hostili
   77 | 2-257849.txt | i/Syrian relations after |more| than 50 years of war and
   54 | 2-257815.txt | en in a state of war for |more| than 50 years.   State D
   37 | 2-257784.txt | es in a state of war for |more| than 50 years.   These d
   18 | 2-257726.txt | etween both countries in |more| than 50-years of conflic
   35 | 2-257776.txt | en in a state of war for |more| than 50-years.  Still, A
    5 | 2-257705.txt |                   INTRO: |More| than 70 Tamil Tiger rebe
   42 | 2-257788.txt | ew Orleans Super Dome of |more| than 79 thousand, Tuesda
   47 | 2-257798.txt |  Situations Ministry say |more| than 80-thousand Chechen
   52 | 2-257808.txt |  Situations Ministry say |more| than 80-thousand Chechen
    3 | 2-257703.txt | it.  A packed stadium of |more| than 93-thousand fans tu
   66 | 2-257829.txt | to eradicate polio began |more| than a decade ago. That
   63 | 2-257824.txt |                      For |more| than a decade, India has
   24 | 2-257740.txt |  U-S embassy resulted in |more| than a dozen injuries, t
   56 | 2-257816.txt | a fell to Russian troops |more| than a month ago, after
    2 | 2-257702.txt |             The Crown is |more| than a piece of exhibiti
   16 | 2-257725.txt | apture the capital began |more| than a week ago, federal
   57 | 2-257818.txt | its fourth quarter sales |more| than doubled, but warned
   46 | 2-257795.txt | Industrial Average and a |more| than five-percent declin
   25 | 2-257741.txt | Average lost 140 points, |more| than one percent, closin
   22 | 2-257736.txt |  The C-D-U has set aside |more| than seven-million marks
   71 | 2-257843.txt | osition election rally.  |More| than two dozen people we
   76 | 2-257849.txt | e negotiations stand, so |more| time can be spent on pur
    4 | 2-257703.txt |  could have scored a few |more| times so we wouldn't hav
   40 | 2-257786.txt |  led to information that |more| were on the cargo ship i
   26 | 2-257742.txt | pondent, Barry Wood, has |more|.                        
   49 | 2-257805.txt | s Challiss McDonough has |more|.                        
   75 | 2-257849.txt | st means we'd like to do |more|.  So we're trying to acc




3.  書式 (%-25.25s など) を変えて実行し,意図通りの出力結果になっているか確認しなさい。

kwic1-112.pl
----------     ----------
$string = '\bmore\b';
$/ = "";

while(<>){

   s/ *\n */ /g;

   while(/$string/ig){
      $count++;

      $key  =  $&;
      $pre  =  substr ($`, -35);
      $post =  substr ($', 0, 35);

      $file =  $ARGV;
      $file =~ s#.*/([^/]+)$#$1#;

      printf "%3d | %s | %35s|%s|%-35.35s\n",
              $count, $file, $pre, $key, $post;
   }
}
exit;
----------     ----------

 > perl script/kwic1-112.pl voa/* | sort -f -t "|" -k 4
......

 61 | 2-257821.txt | t there was also time for broader, |more| philosophical questions.          
  1 | 2-257701.txt |  in New Zealand last September and |more| recently at the Middle East summit
  8 | 2-257716.txt | g businesses and local services in |more| remote parts of the country.  But
 39 | 2-257786.txt | is coincides with the discovery of |more| stowaways on cargo ships in Los An
 73 | 2-257846.txt | ironment.  They say there has been |more| strict enforcement of laws regulat
 33 | 2-257773.txt | the second, ballots will go out to |more| than 10-thousand voting members.  
 68 | 2-257835.txt |  escape the capital. Officials say |more| than 100-rebels died in recent str
 70 | 2-257835.txt | ow more than 450-troops killed and |more| than 15- hundred injured since fig
 44 | 2-257793.txt |                                    |More| than 15-hundred people are known t
 62 | 2-257824.txt | der freed by India in exchange for |more| than 150 hostages aboard a hijacke
 13 | 2-257721.txt | st militants since hijackers freed |more| than 150-hostages New Year's Eve.
 31 | 2-257752.txt |  spiral.  Last year, Beijing spent |more| than 24 billion dollars on such pr
 41 | 2-257786.txt | wners of the  "California Jupiter" |more| than 250-thousand dollars for carr
 12 | 2-257721.txt | t has killed 14-people and injured |more| than 30 others at a market in Indi
 55 | 2-257815.txt | eights - captured by Israel in war |more| than 30 years ago.  Since then, th
 60 | 2-257820.txt | eights - captured by Israel in war |more| than 30 years ago.  The Israeli go
 48 | 2-257801.txt | -River accord, Israel has released |more| than 380 Palestinian and other Ara
 51 | 2-257807.txt |  River accord, Israel has released |more| than 380 Palestinian and other Ara
 19 | 2-257727.txt | i, the U- S Coast Guard is sending |more| than 400 boat people back to Haiti
 69 | 2-257835.txt | ased Russian casualty figures show |more| than 450-troops killed and more th
 23 | 2-257737.txt | contacts between both countries in |more| than 50 years of conflict.        
 59 | 2-257820.txt |  about normalizing relations after |more| than 50 years of hostility, includ
 77 | 2-257849.txt | ure Israeli/Syrian relations after |more| than 50 years of war and confronta
 54 | 2-257815.txt | nically been in a state of war for |more| than 50 years.   State Department
 37 | 2-257784.txt | ir countries in a state of war for |more| than 50 years.   These discussions
 18 | 2-257726.txt |  contact between both countries in |more| than 50-years of conflict.        
 35 | 2-257776.txt | nically been in a state of war for |more| than 50-years.  Still, American me
  5 | 2-257705.txt |                             INTRO: |More| than 70 Tamil Tiger rebels and gov
 42 | 2-257788.txt | d in the New Orleans Super Dome of |more| than 79 thousand, Tuesday night. S
 47 | 2-257798.txt |  Emergency Situations Ministry say |more| than 80-thousand Chechen refugees
 52 | 2-257808.txt |  Emergency Situations Ministry say |more| than 80-thousand Chechen refugees
  3 | 2-257703.txt |  precedes it.  A packed stadium of |more| than 93-thousand fans turned out f
 66 | 2-257829.txt |  campaign to eradicate polio began |more| than a decade ago. That number is
 63 | 2-257824.txt |                                For |more| than a decade, India has been batt
 24 | 2-257740.txt | iot at the U-S embassy resulted in |more| than a dozen injuries, thousands o
 56 | 2-257816.txt | Alkhan-Kala fell to Russian troops |more| than a month ago, after heavy figh
  2 | 2-257702.txt |                       The Crown is |more| than a piece of exhibition. The Hu
 16 | 2-257725.txt | ation to capture the capital began |more| than a week ago, federal commander
 57 | 2-257818.txt | iler said its fourth quarter sales |more| than doubled, but warned this woul
 46 | 2-257795.txt | Dow Jones Industrial Average and a |more| than five-percent decline in the t
 25 | 2-257741.txt | ndustrial Average lost 140 points, |more| than one percent, closing at 11-th
 22 | 2-257736.txt | he party.  The C-D-U has set aside |more| than seven-million marks -- roughl
 71 | 2-257843.txt |  at an opposition election rally.  |More| than two dozen people were killed
 76 | 2-257849.txt | sides where negotiations stand, so |more| time can be spent on pursuing new
  4 | 2-257703.txt | nice if we could have scored a few |more| times so we wouldn't have had to b
 40 | 2-257786.txt |  smuggling led to information that |more| were on the cargo ship in Vancouve
 26 | 2-257742.txt | ics correspondent, Barry Wood, has |more|.                                  
 49 | 2-257805.txt | ty. V-O-A's Challiss McDonough has |more|.                                  
 75 | 2-257849.txt |  but it just means we'd like to do |more|.  So we're trying to accelerate th




4.  出力の書式 (表示する前後の文脈の長さ) も変数で指定し,値を冒頭で指定するように kwic1.pl を書き換えなさい。

kwic1-113.pl
-----------     ----------
$string = '\bmore\b';
$numpre = 20;
$numpost = 50;


$/ = "";

while(<>){
   s/ *\n */ /g;

   while(/$string/ig){

      $count++;

      $key  =  $&;
      $pre  =  substr ($`, -$numpre);
      $post =  substr ($', 0, $numpost);

      $file =  $ARGV;
      $file =~ s#.*/([^/]+)$#$1#;

      printf "%3d | %s | %${numpre}s|%s|%-${numpost}.${numpost}s\n",
              $count, $file, $pre, $key, $post;
   }
}
exit;
----------     ----------



 > perl script/kwic1-113.pl voa/* | sort -f -t "|" -k 4
......

 61 | 2-257821.txt | o time for broader, |more| philosophical questions.                         
  1 | 2-257701.txt |  last September and |more| recently at the Middle East summit in Oslo.      
  8 | 2-257716.txt | d local services in |more| remote parts of the country.  But it is precisely
 39 | 2-257786.txt | th the discovery of |more| stowaways on cargo ships in Los Angeles and Seatt
 73 | 2-257846.txt |  say there has been |more| strict enforcement of laws regulating both factor
 33 | 2-257773.txt | lots will go out to |more| than 10-thousand voting members.                 
 68 | 2-257835.txt | ital. Officials say |more| than 100-rebels died in recent street-fighting.  
 70 | 2-257835.txt | 0-troops killed and |more| than 15- hundred injured since fighting began in
 44 | 2-257793.txt |                     |More| than 15-hundred people are known to have died in
 62 | 2-257824.txt | dia in exchange for |more| than 150 hostages aboard a hijacked Indian airlin
 13 | 2-257721.txt | nce hijackers freed |more| than 150-hostages New Year's Eve.  In return the
 31 | 2-257752.txt | year, Beijing spent |more| than 24 billion dollars on such projects as water
 41 | 2-257786.txt | California Jupiter" |more| than 250-thousand dollars for carrying unregister
 12 | 2-257721.txt | -people and injured |more| than 30 others at a market in Indian Kashmir.  Th
 55 | 2-257815.txt | ed by Israel in war |more| than 30 years ago.  Since then, the Golan has ser
 60 | 2-257820.txt | ed by Israel in war |more| than 30 years ago.  The Israeli government is dem
 51 | 2-257807.txt | Israel has released |more| than 380 Palestinian and other Arab prisoners bei
 48 | 2-257801.txt | Israel has released |more| than 380 Palestinian and other Arab prisoners fro
 19 | 2-257727.txt | st Guard is sending |more| than 400 boat people back to Haiti.  V-O-A's Mich
 69 | 2-257835.txt | sualty figures show |more| than 450-troops killed and more than 15- hundred
 23 | 2-257737.txt | n both countries in |more| than 50 years of conflict.                       
 59 | 2-257820.txt | ing relations after |more| than 50 years of hostility, including security ar
 77 | 2-257849.txt | ian relations after |more| than 50 years of war and confrontation.  The hard
 54 | 2-257815.txt |  a state of war for |more| than 50 years.   State Department Spokesman James
 37 | 2-257784.txt |  a state of war for |more| than 50 years.   These discussions, which opened
 18 | 2-257726.txt | n both countries in |more| than 50-years of conflict.                       
 35 | 2-257776.txt |  a state of war for |more| than 50-years.  Still, American mediators say the
  5 | 2-257705.txt |              INTRO: |More| than 70 Tamil Tiger rebels and government soldier
 42 | 2-257788.txt | leans Super Dome of |more| than 79 thousand, Tuesday night. Scott Harrison h
 47 | 2-257798.txt | ations Ministry say |more| than 80-thousand Chechen refugees have returned t
 52 | 2-257808.txt | ations Ministry say |more| than 80-thousand Chechen refugees have returned t
  3 | 2-257703.txt | A packed stadium of |more| than 93-thousand fans turned out for the 86th edi
 66 | 2-257829.txt | adicate polio began |more| than a decade ago. That number is now down to 30
 63 | 2-257824.txt |                 For |more| than a decade, India has been battling militant I
 24 | 2-257740.txt | embassy resulted in |more| than a dozen injuries, thousands of dollars in pr
 56 | 2-257816.txt | l to Russian troops |more| than a month ago, after heavy fighting.  Accordin
  2 | 2-257702.txt |        The Crown is |more| than a piece of exhibition. The Hungarian Crown s
 16 | 2-257725.txt | e the capital began |more| than a week ago, federal commanders confidently p
 57 | 2-257818.txt | ourth quarter sales |more| than doubled, but warned this would not trim the
 46 | 2-257795.txt | trial Average and a |more| than five-percent decline in the technology-heavy
 25 | 2-257741.txt | ge lost 140 points, |more| than one percent, closing at 11-thousand- 356.  T
 22 | 2-257736.txt | C-D-U has set aside |more| than seven-million marks -- roughly three-and-one
 71 | 2-257843.txt | on election rally.  |More| than two dozen people were killed and scores inju
 76 | 2-257849.txt | otiations stand, so |more| time can be spent on pursuing new ideas rather th
  4 | 2-257703.txt | d have scored a few |more| times so we wouldn't have had to bite our nails (
 40 | 2-257786.txt | to information that |more| were on the cargo ship in Vancouver.   Both of th
 26 | 2-257742.txt | nt, Barry Wood, has |more|.                                                 
 49 | 2-257805.txt | lliss McDonough has |more|.                                                 
 75 | 2-257849.txt | ans we'd like to do |more|.  So we're trying to accelerate the pace.        




練習問題B

1. 検索文字列として「任意の語」が指定できれば,テキスト中のすべての語の KWIC 索引を作ることができることになる。サイズの小さなファイルを選び,すべての語を KWIC 表示しなさい。

 > perl script/kwic1-121.pl voa/2-257850.txt | more
          ※ kwic1-121.pl は元の kwic1.pl の $string 変数に '\b\w+\b' を代入したもの

  1 | 2-257850.txt |                          |DATE           |=1/6/2000 TYPE=CORRESPOND
  2 | 2-257850.txt |                     DATE=|1              |/6/2000 TYPE=CORRESPONDEN
  3 | 2-257850.txt |                   DATE=1/|6              |/2000 TYPE=CORRESPONDENT
  4 | 2-257850.txt |                 DATE=1/6/|2000           | TYPE=CORRESPONDENT REPOR
  5 | 2-257850.txt |            DATE=1/6/2000 |TYPE           |=CORRESPONDENT REPORT TIT
  6 | 2-257850.txt |       DATE=1/6/2000 TYPE=|CORRESPONDENT  | REPORT TITLE=GOVERNORS I
  7 | 2-257850.txt | /2000 TYPE=CORRESPONDENT |REPORT         | TITLE=GOVERNORS ISLAND D
  8 | 2-257850.txt | YPE=CORRESPONDENT REPORT |TITLE          |=GOVERNORS ISLAND DEVELOP
  9 | 2-257850.txt | RRESPONDENT REPORT TITLE=|GOVERNORS      | ISLAND DEVELOPMENT (L ON
 10 | 2-257850.txt | T REPORT TITLE=GOVERNORS |ISLAND         | DEVELOPMENT (L ONLY) NUM
 11 | 2-257850.txt | T TITLE=GOVERNORS ISLAND |DEVELOPMENT    | (L ONLY) NUMBER=2-257850
 12 | 2-257850.txt | NORS ISLAND DEVELOPMENT (|L              | ONLY) NUMBER=2-257850 BY
 13 | 2-257850.txt | RS ISLAND DEVELOPMENT (L |ONLY           |) NUMBER=2-257850 BYLINE=
 14 | 2-257850.txt | AND DEVELOPMENT (L ONLY) |NUMBER         |=2-257850 BYLINE=MARTIN B
 15 | 2-257850.txt | ELOPMENT (L ONLY) NUMBER=|2              |-257850 BYLINE=MARTIN BUS
 16 | 2-257850.txt | OPMENT (L ONLY) NUMBER=2-|257850         | BYLINE=MARTIN BUSH DATEL
 17 | 2-257850.txt | (L ONLY) NUMBER=2-257850 |BYLINE         |=MARTIN BUSH DATELINE=NEW
 18 | 2-257850.txt | ) NUMBER=2-257850 BYLINE=|MARTIN         | BUSH DATELINE=NEW YORK C
 19 | 2-257850.txt | R=2-257850 BYLINE=MARTIN |BUSH           | DATELINE=NEW YORK CONTEN
 20 | 2-257850.txt | 57850 BYLINE=MARTIN BUSH |DATELINE       |=NEW YORK CONTENT=       
......

419 | 2-257850.txt |  York State and New York |City           |. (Signed)               
420 | 2-257850.txt | tate and New York City. (|Signed         |)                        
421 | 2-257850.txt |                          |NEB            |/NY/MAB/JC/ENE/gm        
422 | 2-257850.txt |                      NEB/|NY             |/MAB/JC/ENE/gm           
423 | 2-257850.txt |                   NEB/NY/|MAB            |/JC/ENE/gm               
424 | 2-257850.txt |               NEB/NY/MAB/|JC             |/ENE/gm                  
425 | 2-257850.txt |            NEB/NY/MAB/JC/|ENE            |/gm                      
426 | 2-257850.txt |        NEB/NY/MAB/JC/ENE/|gm             |                         
427 | 2-257850.txt |                          |06             |-Jan-2000 15:59 PM EDT (0
428 | 2-257850.txt |                       06-|Jan            |-2000 15:59 PM EDT (06-Ja
429 | 2-257850.txt |                   06-Jan-|2000           | 15:59 PM EDT (06-Jan-200
430 | 2-257850.txt |              06-Jan-2000 |15             |:59 PM EDT (06-Jan-2000 2
431 | 2-257850.txt |           06-Jan-2000 15:|59             | PM EDT (06-Jan-2000 2059
432 | 2-257850.txt |        06-Jan-2000 15:59 |PM             | EDT (06-Jan-2000 2059 UT
433 | 2-257850.txt |     06-Jan-2000 15:59 PM |EDT            | (06-Jan-2000 2059 UTC) N
434 | 2-257850.txt | 6-Jan-2000 15:59 PM EDT (|06             |-Jan-2000 2059 UTC) NNNN
435 | 2-257850.txt | an-2000 15:59 PM EDT (06-|Jan            |-2000 2059 UTC) NNNN     
436 | 2-257850.txt | 000 15:59 PM EDT (06-Jan-|2000           | 2059 UTC) NNNN          
437 | 2-257850.txt | 5:59 PM EDT (06-Jan-2000 |2059           | UTC) NNNN               
438 | 2-257850.txt | PM EDT (06-Jan-2000 2059 |UTC            |) NNNN                   
439 | 2-257850.txt | T (06-Jan-2000 2059 UTC) |NNNN           |                         
440 | 2-257850.txt |                          |Source         |: Voice of America .     
441 | 2-257850.txt |                  Source: |Voice          | of America .            
442 | 2-257850.txt |            Source: Voice |of             | America .               
443 | 2-257850.txt |         Source: Voice of |America        | .          




2. kwic1.pl では段落を単位としているので,段落先頭の語の前の文脈,段落末の語の後ろの文脈は表示できない。段落を越えた文脈が表示できるよう,スクリプトを書き換えなさい。段落の境界をどう表示するかも考えること。


kwic1-122.pl
----------     ----------
$string = '\bjust\b';

$/ = undef;
while(<>){

   s/ *\n\n+ */ <par> /g;
   s/ *\n */ /g;

   while(/$string/ig){
      $count++;

      $key  =  $&;
      $pre  =  substr ($`, -25);
      $post =  substr ($', 0, 25);

      $file =  $ARGV;
      $file =~ s#.*/([^/]+)$#$1#;

      printf "%5d | %s | %25s|%s|%-25.25s\n",
              $count, $file, $pre, $key, $post;
   }
}
exit;
----------     ----------

 > perl script/kwic1-122.pl voa/* | more
    1 | 2-257703.txt |  gave us momentum and we |just| carried it on.  It would
    2 | 2-257706.txt | he said the war has only |just| begun. <par> Russian tro
    3 | 2-257713.txt | eters from Washington is |just| a brief helicopter ride
    4 | 2-257728.txt | , in part, because it is |just| a half-hour helicopter r
    5 | 2-257730.txt |  to Lisbon traded shares |just| as they did in 1999. <pa
    6 | 2-257731.txt | e-maker.  The dismissal, |just| three-days after Mr. Put
    7 | 2-257736.txt |  looks as if it could be |just| the beginning for invest
    8 | 2-257736.txt | int-one-million marks -- |just| over 500-thousand dollar
    9 | 2-257737.txt | oops from the Golan, but |just| how much territory Israe
   10 | 2-257748.txt | onday.  The problem came |just| hours after President Cl
   11 | 2-257748.txt | roops from the Golan but |just| how much territory Israe
   12 | 2-257755.txt | eeling he had been given |just| a few more hours to live
   13 | 2-257757.txt |  to 19-thousand-and-two, |just| above the psychologicall
   14 | 2-257764.txt | n in October, saying she |just| could not match Mr. Bush
   15 | 2-257769.txt | ficult issues. And we'll |just| have to hope that we'll
   16 | 2-257770.txt | <par> Dore Gold, who has |just| returned to Jerusalem af
   17 | 2-257770.txt | > The meeting took place |just| days before the arrival
   18 | 2-257773.txt |  The musician had earned |just| one Grammy and five nomi
   19 | 2-257781.txt | rage dropped 359 points, |just| over three percent, clos
   20 | 2-257781.txt | rld as we know it. But I |just| think that a number of t
   21 | 2-257804.txt |  Opposition parties, who |just| a few-weeks ago conteste
   22 | 2-257815.txt | fficult issues and we've |just| gotten started in that k
   23 | 2-257815.txt |  begun discussions about |just| what the costs of any pe
   24 | 2-257816.txt | , two strategic villages |just| southwest of Grozny, say
   25 | 2-257816.txt | olumn - and the Russians |just| let them back without a
   26 | 2-257816.txt |  "We wish this war would |just| stop.  We'll be satisfie
   27 | 2-257818.txt | age gained 124 points or |just| over one percent, recove
   28 | 2-257842.txt | "Month of Africa" is not |just| a gimmick, and the futur
   29 | 2-257847.txt | ar> MOTORIST # 1:  "It's |just| a pain in the butt for n
   30 | 2-257847.txt | GA ACT /// <par> This is |just| the beginning.  And I kn
   31 | 2-257848.txt | in office has slipped to |just| nine percent. A recent s
   32 | 2-257849.txt | of closing of the gaps - |just|, as he put it, more "chu
   33 | 2-257849.txt | ing is happening, but it |just| means we'd like to do mo