Notes & TILs
Search…
grep cheatsheet
Posted on 15 Dec, 2021
Will be logging here various uses-cases of grep
  1. 1.
    Print anything between 2 patterns
    1
    # print all function names inside a python files
    2
    grep -o -P '(?<=def ).*?(?=\()' demo.py
    Copied!
  2. 2.
    Ignore more than one pattern from search
    1
    # ignore json and py files from output
    2
    # -v means invert-match
    3
    # -E activates extended regexp patterns (egrep). Allows use of symbols like +, |, ?
    4
    ls | grep -Ev '(.json|.py)'
    5
    # this is same as
    6
    ls | grep -v -e .json -e .py
    Copied!
Last modified 1mo ago
Copy link