grep search in files code example

Example 1: linux search for a given string in all files recursively

$ grep -r "String to be searched goes here" *

Example 2: linux search for line in file

grep -R "keyword" /directory/

Example 3: linux find from file content

grep -rnw '/path/to/somewhere/' -e 'pattern'

Example 4: read string by string in file in linux

grep 'word' filename
grep 'word' file1 file2 file3
grep 'string1 string2'  filename
cat otherfile | grep 'something'
command | grep 'something'
command option1 | grep 'data'
grep --color 'data' fileName

Tags:

Cpp Example