From what I can tell from your post, you'll need two things. Firstly, you need a way to grab the individual ID's from the log.txt file, and secondly, you want to grab 1 line before that ID in log.txt, and 1 line after the match in output.txt.
You can use grep for both of these. First off, use the '-o' option to just grab the ID using a suitable regexp. Then strip out the ID (not sure if this is needed, but better safe than sorry). Something like
Code:
grep 'ID: *[0-9]\+' | sed 's/ID: *//'
This'll match 'ID:' followed by 0 or more spaces (' *'), followed by a number of 1 or more digits ('[0-9]\+'). The 'sed s/ID: *//' then removes the ID: and spaces from the line, leaving just the number.
So having got the individual ID's, you then want to extract lines before in the log.txt, and lines after in output.txt. This is easily achieved using the '-A' and '-B' options in grep (lines after and before).
So putting it all together:
Code:
for x in $( grep -o 'ID: *[0-9]\+' log.txt | sed 's/ID: *//' );
do
echo -----------------------------
linebefore=$(grep -B 1 $x log.txt)
lineafter=$(grep -A 1 $x output.txt)
echo "${linebefore}"
echo "${lineafter}"
done
The above is just based on what you posted, and will probably need editing. For instance, it assumes that the ID number will only ever exist in output and log as the actual ID, not as just a number. It might be worth removing the pipe to sed, but then the spaces between ID: and the number need to match between log.txt and output.txt. It also assumes every ID in log.txt has a corresponding entry in output.txt. Still, maybe it's a start.
Hope you follow what's happening.