Searching inside a .gz file without gunzip

I have a set of folders inside which there may be n number of files. All those files are in .gz extension. Now I need to search all the files without gunzip them. Also I need to read the content of a file if the search pattern is found without gunzip them.

It's impossible to read gzipped files without gunzipping them. If you don't want change gzipped files use

zcat

OR

gunzip -c

Could you please explain?

for f in *.gz; do
  if  zcat "$f" | grep -q pattern ; then
    var=`zcat "$f"`
    # do something with $var or just use the result of zcat in a pipe or do something with "$f"
done

If you have zgrep then use it - if zgrep -q pattern "$f" ; then ... . If you don't have zcat use gunzip -c "$f" .