Search

xzgrep for searching in compressed files

grep is a very powerful tool for everyone who works with text and strings. For searching through logs, errors and other text based data. But if the same data is present inside a compressed archive, like .bz2 or a .xz. Then we need to uncompress it and then use grep on the files.

If the number of such compressed files are too many, uncompressing all of them with out knowing which one contains the data that we are looking for could be a waste of time. This is were xzgrep can come to rescue.

xzgrep can search through compressed files of the formar .bz2,.xz etc and look for strings in the files like grep does. The only difference is that xzgrep can only confirm whether the search string is present in the compressed file or not and not be able to list further details like grep does.

For example let us take two files

hello1



hello2



Let us create a tar file



Compress it using bunzip



This will create the compressed file hello.tar.bz2

Now to search for text inside this compressed file.



The string 12 is present is hello1 thus the ouput says that a match is found.



If match is not found, xzgrep does not mention any thing.

But note that the xzgrep works only on the text files inside the compressed file, like grep works only on text files. Thus if the search string is inside a pdf or any other document, xzgrep will not be able to pick it up.


2 comments: