# grep a word in a tar.gz file



## prernabhagat (Nov 22, 2007)

Can anyone tell me how to search a word in files which have been zipped in a tar file using the tar -zcvf command.............


----------



## RobLinux (Nov 7, 2007)

I think you mean something like :

f=/some/foo/bar
d=/tmp/$USER/tar$$
mkdir -p $d || {
echo Could not create $d 1>&2
exit 1
}
cd $d && tar -zxf $f && {
find . -type f -print0 | xargs -0 fgrep /word/
echo rm -rf $d | at now + 5 minutes
}

Haven't debugged it, so you might like "set -x" shell option, and "xargs -t" to trace files. Clean up should be run, on keyboard interrupts like when CNTRL-C is hit, which you do with trap(1) and a shell proecedure.


----------

