Read specific content file from tar.gz files without extracting

Solution 1:

As mentioned in the comments, you need to use zgrep on compressed archives, however what you're doing is adding -r to the options list, which is not supported by zgrep which comes with Ubuntu.

-r is used for recursive traversal of directory tree. We can do the same with find command, and use -exec flag to run zgrep on each compressed archive that is found.

Since I don't have any example of archives you use, the command below is just an example. Adjust as necessary:

find -type f -name "*.tar.gz" -exec zgrep -a "ERROR24" /home/tests/logs > /home/files/data/result/listErrors.txt  \;

Note that -l here can't really be used, because it only lists filename of archive itself. Alternatively, you could always use zcat and filter its output with grep, but that's probably more hassle than necessary.