Skip to content

Instantly share code, notes, and snippets.

@r-winkler
Last active October 17, 2016 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r-winkler/057a8a1207505af03cfb6f157234d1a2 to your computer and use it in GitHub Desktop.
Save r-winkler/057a8a1207505af03cfb6f157234d1a2 to your computer and use it in GitHub Desktop.
# Show grep version
grep --version
# Print lines containing sys
grep sys /etc/passwd
# Print lines containing SYS case insensitive
grep SYS -i /etc/passwd
# Count lines containing sys
grep -c sys /etc/passwd
# Print last 10 lines containing sys
tail -10 /etc/passwd | grep sys
# Print lines fullfilling regex (put regex in single quotes)
grep '^[a-z]' /etc/passwd
# Print non empty lines
grep -v '^$' /etc/passwd
# Print 2 lines after the match (including the match)
# use B instead for before, C for before and after
grep proxy -A2 /etc/passwd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment