Print only the matched part

Extract unique IP addresses from a log with a Perl regex

grep -oP '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}' access.log | sort -u

tool
grep15 commands
tags
grep

More grep commands

  • grep -v '^#' /etc/nginx/nginx.conf | grep -v '^\s*$'

    Show a config file without comments and blank lines

  • grep -r --include='*.py' 'import os' /srv/app/

    Limit a recursive search to .py files

  • grep -r --exclude-dir='.git' --exclude-dir='node_modules' 'TODO' .

    Search recursively but skip .git and node_modules

  • grep -rn 'panic:' /var/log/app/

    Show the file and line number for each match

  • rg 'TODO|FIXME|HACK' --type py -l

    List Python files that contain TODO, FIXME or HACK

all 15 grep commands