Last active
September 27, 2020 17:36
-
-
Save schneefisch/3f960f545947524e43bcfc9347704f3b to your computer and use it in GitHub Desktop.
search in multiple compressed files with zgrep
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# grep over several zipped files | |
# in this case with with two search words "SEARCH1" OR "SEARCH2" | |
# it will also sort the entries and open them in "less" to view as a document | |
zgrep "SEARCH1\|SEARCH2" /application/logs/2019/03/app_*17.03.30*.gz|cut -d : -f 2-|sort --stable --key 1,1 |less | |
# E.G. search for "Exception | |
zgrep "Exception" /application/logs/2019/03/app_*17.05.*.gz|cut -d : -f 2-|sort --stable --key 1,1 |less | |
# to count the output lines, add following pipe at the end, instead of | less | |
| wc -l | |
# HowTo search in multiple gzip files without extracting them: | |
find . -name "*.gz" -exec zgrep 'PATTERN-TO-LOOK-FOR' {} \; | |
zgrep -iHn -B 20 -A 10 'PATTERN-TO-LOOK-FOR' $LOGFILE | |
# This command looks for every file with the pattern *.gz. For every file it’ll execute the zgrep command and looking for the "PATTERN-TO-LOOK-FOR“. | |
# | |
# See: http://www.thegeekstuff.com/2011/10/grep-or-and-not-operators/ | |
# and http://stackoverflow.com/questions/21549038/zgrep-multiple-gz-files-in-directory | |
# | |
# http://www.thegeekstuff.com/2011/10/grep-or-and-not-operators/ | |
#/application/logs/data/WEBAPPS/PROD/sedcajcdwpa0/pwtool_L0-member0-0/2019/04/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment