Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Grep, awk and sed

Stop after 1 match

grep -m 1 'pattern' filename

Grep for 2 things

grep 'pattern1\|pattern2' fileName_or_filePath

Filter out comments and blank lines

grep -Ev "^#|^$" filename

Display lines before or after result

grep -A 5 'pattern' filename # Display 5 lines after the result
grep -B 5 'pattern' filename # Display 5 lines before the result
grep -C 5 'pattern' filename # Display 5 lines before and after the result

Less can also highlight

k -n project-c13 describe pod | less -p Requests # describe all pods and highlight Requests