Bash

Grep

Syntax#

  • grep [OPTIONS] PATTERN [FILE…]

How to search a file for a pattern

To find the word foo in the file bar :

grep foo ~/Desktop/bar

To find all lines that do not contain foo in the file bar :

grep –v foo ~/Desktop/bar

To use find all words containing foo in the end (WIldcard Expansion):

grep "*foo" ~/Desktop/bar


This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow