Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search tar files

Status
Not open for further replies.

craig322

MIS
Apr 19, 2001
108
0
0
US
Is there a way to grep through files in a tar file without extracting the files? The tar file resides on disk if that makes any difference.
 
try
Code:
tar -tf path/to/tarfile.tar | grep file_I_want

Columb Healy
 
May want to do:

tar -tvf path/to/tarfile.tar | grep desired_file

 
I think he is looking for the content of the file, not the filename.

here is a script targrep.sh:
Code:
#!/bin/bash
#
# usage: targrep.sh pattern tarfile
#
mkdir /tmp/untar
tar -xf $2 -C /tmp/untar
grep -R $1 /tmp/untar
rm -rf /tmp/untar

seeking a job as java-programmer in Berlin:
 
If you want to check the contents of a tar file without extracting you can use 'strings'. It won't tell you which file contains the string but it will tell youif it's there.

To test this I tarred up a number of *.c files and then
Code:
$ strings bits.tar | grep include
#include <stdio.h>
#include <error.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top