grep a tar file

grepping a xyz.tar.gz file?

how to grep a xyz.tar.gz file on unix box?

i moved it to loical using winscp.

how to extract it to see file contents

i used qizip and 7 zip they simply changing zip to tar and then tar to zip again and again

please advise
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dr. KlahnPrincipal Software EngineerCommented:
grepping a xyz.tar.gz file?

The file must be decompressed in order to turn it back into a TAR file, e.g. for a gzipped file, gzip -d <xyz.tar.gz>

The TAR file should then be unTARed to extract the contents, e.g., tar -xvf <xyz.tar>.  It's possible to grep the TAR file itself, but if the TAR file contains multiple files and there is a match - there's no way to tell which of the files in the archive contains the target string.

Depending on the version of tar available, there may be a direct switch to extract from a compressed tar file; use "man tar" to find out.

Finally grep the unTARed contents, e.g. grep <regex> *

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nociSoftware EngineerCommented:
tar.gz can be read in one go:
(x = extract, z = gunzip, v = show what you do, f next argument in input file)
tar xzvf {xyz.tar.gz}      # don;t use { }...  

(t = test, z = gunzip, v = verbose, f = next is file) - testing will show the contents of a tar.
tar tzvf {xyz.tar.gz}    

What do you want to know..., if some word occurs in the tar as such? then grepping .tar file makes sense
zcat {xyz.tar.gz} | grep the-word

if you want some specific file checked..., then you need to unpack.
gudii9Author Commented:
tar xzvf xyz.tar.gz

showing bunch of files there like


what are all those files

how do i grep on ./xyxstuff-2018-02-24 which is more important to me?
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

Travis MartinezStorage EngineerCommented:
The above comments are probably what you're looking for; however, if you would like to unpack and/or change the extension try using WinRAR.  I'm fairly confident though you have to unpack it first with WinRAR before you can change the extension of the file.
Dr. KlahnPrincipal Software EngineerCommented:
how do i grep on ./xyxstuff-2018-02-24 which is more important to me?

See my comment above, and instead of grepping on *, grep on the filename.
Tar is an archive, gz means it is compressed similar to placed in a box and sealed.

Winrar if not mistaken includes untar functionality.

As others pointed out you gave to unseal, unpack box and only then look through to files ...

While Linux/UNIX is command line oriented, grep get look at the data stream, what is the data that you want

unless you do two things, 1 prior to archiving, catalog, index the files such that you have the archive, file.tar.gz and the other index_catalog.gz
As a hash, cdb, etc. then when searching if pattern is in file.tar.gz, you would search for the pattern in the index as that would be smaller space......
That will tell if there are matches and when they exists the files in which they San ve located.
nociSoftware EngineerCommented:
grep someword ./xyxstuff-2018-02-24

maybe using view/notepad/wordpad/ultraedit/... show more in the case of ascii data.
A tar file is just basically a concatenation of files with some dividers in it.  A tar.gz is a tar file that's been compressed.  If the tar'd portion is plain text, you can use zgrep, if you have zcommands installed on your system.

zgrep <search_term> xyz.tar.gz
Seth SimmonsSr. Systems AdministratorCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: Dr. Klahn (https:#a42481531)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

Experts-Exchange Cleanup Volunteer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.