Skip to content

Instantly share code, notes, and snippets.

@fieldse
Created November 15, 2020 10:13
Show Gist options
  • Save fieldse/24afdc852eaeb6622976a4098b64e1f7 to your computer and use it in GitHub Desktop.
Save fieldse/24afdc852eaeb6622976a4098b64e1f7 to your computer and use it in GitHub Desktop.
Grep/zgrep: count matches across multiple files
# Count occurences of KEYWORD across all files named [something].log
# Flag: -src
# Credit:
# https://superuser.com/questions/205591/show-the-matching-count-of-all-files-that-contain-a-word
grep -src KEYWORD *.log
# Example output:
# production.20201107.log:12
# production.20201108.log:0
# production.20201109.log:0
# production.20201110.log:0
# production.20201111.log:0
# production.20201112.log:21
# Zgrep: Count occurences of KEYWORD across gzipped files
# Same syntax
zgrep -src KEYWORD *.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment