Skip to content

Instantly share code, notes, and snippets.

@shaunakv1
Last active December 5, 2024 05:53
Show Gist options
  • Save shaunakv1/ba1a6ce0e1c1df8b885544be03c760ee to your computer and use it in GitHub Desktop.
Save shaunakv1/ba1a6ce0e1c1df8b885544be03c760ee to your computer and use it in GitHub Desktop.
Grep command to search through files

Look for lines in a log files by IP address

grep '^98.97.40.8 ' access_main.log > /var/tmp/clipping.log

search through gz files

zgrep '^34.234.176.30 ' access_main.log-202411*.gz access_main.log-20241107 access_main.log > /var/tmp/clipping.log

prints the top-ten IP numbers in the access log

cat access_main.log | awk '{print $1}' | sort | uniq -c | sort -nr | head -10

print first few lins from a file

head -n 10 some.csv

Count the lines with instances of a word in a file

grep 'WORD' some.csv | wc -l

How many of these instances are between a timeframe

grep 'WORD' some.csv | grep -E '2022-12-01T03:[0-5][0-9]:[0-5][0-9]' | wc -l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment