script,awk,sed question?

Shutoku Shia smileyf at ucscb.UCSC.EDU
Sun Jul 3 09:56:02 AEST 1988


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 at ucscf.bitnet         |    formerly in              |
| Internet:  smileyf at ucscf.UCSC.EDU     | Dept. of Cmp. & Info. Sci.  |
| Arpanet: smileyf at ucscf.UCSC.EDU       | Univ. of Calif., Santa Cruz |
| Uucp:  ...!ucbvax!ucscc!ucscf!smileyf |                             |
-----------------------------------------------------------------------



More information about the Comp.unix.wizards mailing list