Match part of string in file2 based on column in file1

I have a file containing texts and indexes. I need the text between (and including ) INDEX and number "1" alone in line. I have managed this:

awk '/INDEX/,/1$/{if (!/1$/)print}' file1.txt

It works for all indexes.

And then I have second file with years and indexes per year, one per line

1990 INDEX1 ....
1990 INDEX2 .....

I need all indexes for a given year (and ONLY for a given year). I have managed this, too:

awk 'BEGIN {while (getline < "indexes.txt") {if ($1=="1990") print $2} }';

What I'd like to do is join the two- so that I would get all the texts from file1 that match indexes printed by second command.
any ideas?

I guess your requirement is unclear for other members in this forum including me.

I would suggest you to post a sample input and desired output in code tags

OK, thanks...
So, as I said, I have two input files.
The first ("yearly book") is structured like this:

1.01 text I would
like to extract
(including newlines etc.)
1
2
3
(....text I don't need...)
1.02 some more text I would like to extract
in more than one line, again and terminator
is "1" in line
1
2
...

I managed this using:

awk '/1\.01/,/1$/{if (!/1$/)print}' file1.txt

I have hundreds if those "indexes" (1.01, 1.02,...) and doing it manually would be nonsense.
I also have file with list of them in file with all indexes of all yeary books structured like this:

1990 1.01 some description I don't need
1990 1.02 more desc...
(...)
1991 1.0 some desc I don't need

I've managed to extract all indexes for given year:

awk 'BEGIN {while (getline < "indexes.txt") {if ($1=="1990") print $2} }';

What I would like to do is join the two commands (or write a combined one) so it would pass all "indexes" from the command below into the command aboce and I would get all texts from file1 I need...

If I understand what you're trying to do, the following seems to work:

!/bin/ksh
year=${1:-1990}
awk -v y="$year" '
FNR == NR && $1 == y {
        # Save index...
        idx[$2]
        next
}
$1 in idx,$1 == 1 {
        if($1 != 1) print
}' indexes "yearly book"

If you're using a Solaris/SunOS system, use /usr/xpg4/bin/awk , /usr/xpg6/bin/awk , or nawk instead of awk .

With the input files specified in the 1st message in this thread, the output produced is:

1.01 text I would
like to extract
(including newlines etc.)
1.02 some more text I would like to extract
in more than one line, again and terminator
is "1" in line

when the script is invoked with no operands and when it is invoked with the operand "1990".