Software Helpful Commands For Searching Archives Without Extracting

Software Helpful Commands For Searching Archives Without Extracting

notagh0st

User
User ID
28962
Sep 9, 2023
15
41
#CR
34
  • Thread starter
  • Thread Author
  • #1
We all often deal with large archives that we might want to search without having to extract the files from it. Here are the commands that I've found most useful for each type or archive.

HTML:
# gz
gunzip -c archive.gz | grep "search text" > out.txt

# 7z
7z e -so archive.7z | grep "search text" > out.txt

# zip
unzip -p archive.zip | grep "search text" > out.txt

# rar
unrar p archive.rar | grep "search text" > out.txt

You could remove the
HTML:
> out.txt
from the end to see the grep results being piped to stdout.

Some additional flags on the grep that might be useful:

HTML:
# grep which allows literal interpretations of punctuating marks like periods (whereas before, periods would be interpreted as regex parts)
grep -F "search text"

# when grep finds a match, get n number of lines above and below the match
grep -C 1 "search text"
 
between this method and extracting a large file, which would you find worth in terms of efficiency?
 
Back
Top Bottom