Xref: utzoo comp.unix.questions:7933 comp.unix.wizards:9726
Path: utzoo!attcan!uunet!husc6!uwvax!oddjob!ncar!gatech!hubcap!ncrcae!ncr-sd!hp-sdd!hplabs!ucbvax!agate!saturn!ucscb.UCSC.EDU!smileyf
From: smileyf@ucscb.UCSC.EDU (Shutoku Shia)
Newsgroups: comp.unix.questions,comp.unix.wizards,ca.unix
Subject: Re: script,awk,sed question?
Keywords: script awk sed unix
Message-ID: <4006@saturn.ucsc.edu>
Date: 2 Jul 88 23:56:02 GMT
References: <24707@oliveb.olivetti.com>
Sender: usenet@saturn.ucsc.edu
Reply-To: smileyf@ucscb.UCSC.EDU (Shutoku Shia)
Organization: University of California, Santa Cruz; CATS
Lines: 60

Here's one way to do it using awk.  I had to make several assumptions
about the input format in order to do it:
(1) the two input files are named "file.a" and "file.b" (double quotes
    not included).
    This means the command to invoke the awk script is like the
    following:
    %awk -f fun.awk file.a file.b
(2) the field delimiter in awk has been set to "' " (double quote not
    included).  This means the string cannot have "' " inside the it.
(*) there is a new version of awk, however, I tested the following
    awk script using the old version on BSD UNIX 4.3 running on 
    VAX 11/750.

% cat fun.awk
BEGIN {
   file_a = "file.a"
   file_b = "file.b"
   FS = "' "
   list_a_size = 1
   list_b_size = 1
}

FILENAME == file_a {
     list_a[list_a_size++] = $2
}
FILENAME == file_b {
     list_b[list_b_size] = $2
     number[list_b_size++] = $3
}

END {
   for(a = 1; a < list_a_size; ++a) {
      for(b = 1; b < list_b_size; ++b)
         if (list_a[a] == list_b[b])
	    print list_a[a] ":" number[b]
   }
}
% cat file.a
with 'string 1' #5
     'string 5' #1
% cat file.b
with 'string 1' #1
     'string 2' #2
     'string 3' #3
     'string 4' #4
     'string 5' #5
% awk -f fun.awk file.{a,b}
string 1: #1
string 5: #5
% 
% 

	Shutoku Shia

-----------------------------------------------------------------------
| Bitnet:  smileyf@ucscf.bitnet         |    formerly in              |
| Internet:  smileyf@ucscf.UCSC.EDU     | Dept. of Cmp. & Info. Sci.  |
| Arpanet: smileyf@ucscf.UCSC.EDU       | Univ. of Calif., Santa Cruz |
| Uucp:  ...!ucbvax!ucscc!ucscf!smileyf |                             |
-----------------------------------------------------------------------