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:
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".