Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 395 Vote(s) - 3.43 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I grep for a text pattern in a zipped text file?

#1
Our daily feed file averages 2 GB in size. These files get archived to a single zip file at the end of each month and stored in a network share. From time to time, I have a need to search for certain records in those files. I do this by connecting by remote desktop to the shared server, unzip the files to a temp folder, run grep (or PowerShell) search, and then delete the temp folder. Now, because our server is running low in disk space, it is no longer recommeded to unzip them all to a temp folder. What is an efficient way to do a regex search on those zipped files with minimum impact on disk or network resources?





Reply

#2
There are some zip related commandlets in the Powershell Community Extensions [(PSCX)][1]. I don't think they would do what you want however (I could be entirely wrong about that though). Instead I would use .Net Zip Library [(DotNetZip)][2] which allows you to essentially list the names of the files in an archive then extract just the ones you want.


[1]:

[To see links please register here]

"(PSCX)"
[2]:

[To see links please register here]

"DotNetZip"
Reply

#3
The [PowerShell Community Extensions][1] (PSCX) include `Read-Archive` and `Expand-Archive` cmdlets, but don't (yet?) include a navigation provider which would make what you want very simple. That said, you could use
`Read-Archive` and `Expand-Archive`. Something like this untested bit

Read-Archive -Path foo.zip -Format Zip | `
Where-Object { $_.Name -like "*.txt" } | `
Expand-Archive -PassThru | select-string "myRegex"

would let you search without extracting the entire archive.

[1]:

[To see links please register here]

Reply

#4
[zgrep][1] on Linux. If you're on Windows, you can download [GnuWin][2] which contains a Windows port of zgrep.

[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#5
The suggested zgrep answer above only searches .gz files, not zip files. If you want to grep zip, gz, tar, tgz, bz, lz4, zstd, and other compressed files and archives, then you could use [ugrep](

[To see links please register here]

), which allows to do that with `-z` flag. There is also a ugrep.exe version for Windows in the releases and repo.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through