First, c.f. this page to explain why not to use
for i in `cat list1.txt`
...ever.
Second, this for why not to use
cat list2.txt | awk ...
Sorry to harp. Now...try
while read -r val || [[ -n "$val" ]]
do awk "/$val/ { flag=1; next } /Flag2/ { flag=0 } flag" list2.txt
done < list1.txt
awk
in double-quotes...not ideal.
Or, as Charles suggests, use -v (always listen to Charles & Ed...)
while read -r val || [[ -n "$val" ]]
do awk -v i="$val" '
$0 ~ i { flag=1; next }
/Flag2/ { flag=0; }
flag
' list2.txt
done < list1.txt
Still waiting for file samples. Please give us a peek at the format of these files so I can actually run a valid test.
Note the || [[ -n "$val" ]]
is only needed if there's a chance the last record won't have a newline.