在tar文件中执行grep操作而不解压 [英] Performing grep operation in tar files without extracting
本文介绍了在tar文件中执行grep操作而不解压的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有包含特定模式的文件列表,但这些文件已被压缩.现在我想在 tar 文件中搜索模式,并在不提取文件的情况下知道哪些文件包含该模式.
I have list of files which contain particular patterns, but those files have been tarred. Now I want to search for the pattern in the tar file, and to know which files contain the pattern without extracting the files.
有什么想法...?
推荐答案
tar
命令有一个 -O
开关,可以将您的文件提取到标准输出.所以你可以将这些输出通过管道传输到 grep/awk
the tar
command has a -O
switch to extract your files to standard output. So you can pipe those output to grep/awk
tar xvf test.tar -O | awk '/pattern/{print}'
tar xvf test.tar -O | grep "pattern"
例如返回找到的一种模式的文件名
eg to return file name one pattern found
tar tf myarchive.tar | while read -r FILE
do
if tar xf test.tar $FILE -O | grep "pattern" ;then
echo "found pattern in : $FILE"
fi
done
这篇关于在tar文件中执行grep操作而不解压的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文