(hopefully) the final product
find . -name \*.gz -type f -exec gzcat {} + | sed -ne'/^ *ID:/h;/No Profile/!d;x' \ -e's/^ *ID:\([^ ]*\).*/\1/p'
So that will recursively find all of the regular files rooted in the current directory with filenames which match the pattern *.gz and call zcat as few times as is necessary to iteratively uncompress every one in a single stream to sed's stdin.
sed will scan its input for lines which are headed with the string *ID:. It will hold a copy if found, and next look for No Profile while deleting all lines which don't match. When found sed will swap into hold space and try to trim an ^ *ID: line to only the portion falling between the first : and next occurring <space>. If successful, sed prints the results.
As @DarkHeart points out you will most likely have to alter the zcat command name to gzcat on an HPUX system, though.
variations
This would be all you need to search a single file for line pairs occurring immediately previous to a match for the string No Profile:
gzip -d <file.gz | sed -e'1N;$!N;/\n.*No Profile/P;D'
That will just scan input three lines at a time. Each line is separated by a \newline in pattern space. As each New line is pulled in, the oldest is Deleted. If the regexp \n.*No Profile is ever matched in pattern space (as it will be when it is the newest line in pattern space, and the following cycle when it is the second to newest), the oldest line is printed. And so you get the two lines occurring before No Profile. If you want to also print the line on which it is found...
gzip -d <file.gz | sed -e'1N;$!N;/No Profile/P;D'
with find:
find . -name \*.gz -type f -exec zcat {} + | sed -e'1N;$!N;/No Profile/P;D'
You can swap the . there for the name of some directory if you like. You can also add the \n.*No Profile bit to avoid printing the matching line. That command will recurse into all child directories of .. If that is not to your liking:
find . \! -name . -prune -name \*.gz \ -type f -exec zcat {} + | sed -e'1N;$!N;/No Profile/P;D'
If you are specifically looking for the leading ID field and only if can be found two lines prior to a match for No Profile you can do:
find . -name \*.gz -type f -exec zcat {} + | sed -ne'/^ID/!D;/\n/!N;N' \ -e's/ .*\n.*\n.*No Profile.*//p;D'
...which would print only the leading ID field as it might occur in any/all of the *.gz files find calls zcat to print and only if ID definitely occurs two lines before a No Profile match.
grep --versionand try usinggrep -C2(context)?zgrepgrepas Linux; so you could build and install GNU grep, perhaps configured with--prefix=$HOME/soft/