Taking key values from one file and extracting values from another file

Hi,

I have two files with values in both.

File1 :

cat 2 3
dog 4 5
elephant 6 7 
camel 2 3

File2 :

----+--gkf;ajf=
---+----
+----- cat -------=----+ 3 | 4 ----- dog ------++-- 5 | 9 ----++-- elephant |
5 | 7
---++ camel ------ ++++_---- || 8 | 9

I want the final file as:

cat 4
dog 9
elephant 7
camel 9

The animal values will be taken from file one and used as reference.

File2 is all messed up and the only real separator is | .

Thanks.

Let's start with the basics:

  1. What have you tried to solve this problem on your own?
  2. What operating system are you using?
  3. What shell are you using?

Then we can move on to the thread specifics:

  1. What is the field separator in File1 ? I assume it isn't a <space>, or do you disallow animals like mountain lion, Asian elephant, African elephant, eastern diamondback rattlesnake, western diamondback rattlesnake, timber rattlesnake, etc. from your representable data?
  2. How is one supposed to determine what number is to be associated with an animal? If we ignore <newline>s as field and/or record separators, you still have most numbers coming from the text somewhere between the 2nd and 3rd <vertical-bar> character following the field that contains the animal name surrounded by <space>s. Sometimes there are three <vertical-bar>s between the string containing the animal and the string containing the number said should appear in the output.