Closed huornlmj closed 6 months ago
If you only want to recursively search for tar files and then list the files in those that match a pattern:
ug -rl -Otar "" | xargs ug -lz "PATTERN"
This runs a ugrep to simply look for tar files recursively with ug -rl -Otar ""
and a second ugrep to list each of the tar contents with ug -lz "PATTERN"
to match PATTERN
in files stored in tar files. I am using ug
here to pretty print and sort the tar files (option --sort
). With ugrep
use the following to sort tar files by name (or specify a sort key):
ugrep --sort -rl -Otar "" | xargs ugrep -lz "PATTERN"
Note that the problem with using --include="*.tar"
(same as -Otar
) is that you only select tar files to search, which also only searches tar files inside tar files when you use option -z
. Option -z
must be used to search inside tar, tarballs, zip files and compressed files.
Did that work for you? If so, can this be closed?
Using xargs
for this scenario is not uncommon, because it involves two conflicting search criteria, one to find tar files and the other to search the tar files.
Yes that worked perfectly! Many thanks. Closing now.
I'm searching for a phrase inside files that are themselves inside tar files which are scattered throughout a number of sub directories.
What I get in output is:
What I want is not to see the name of the file inside the tar file that the phrase was in. For example:
dir1/tarfile.tar
has a file in it called/home/user/thefile.txt
and it contains the phrase "phrase" that I'm searching for. I want to see the name of the "/home/user/thefile.txt
" as well as the name of thedir1/tarfile.tar
file.