how to grep in linux code example
Example 1: how to grep
grep 'word' filename
fgrep 'word-to-search' file.txt
grep 'word' file1 file2 file3
grep 'string1 string2' filename
cat otherfile | grep 'something'
command | grep 'something'
command option1 | grep 'data'
grep --color 'data' fileName
grep [-options] pattern filename
fgrep [-options] words file
Example 2: linux grep
# EXAMPLE 1: look for any files (with names ending in ".c++") for the text "::MethodA("
grep "::MethodA(" *.c++
# EXAMPLE 2: display only the matching file names (not the row too) of the matches
grep -l "MethodA(" *.c++
# SYNTAX
# grep [optional-filters] "<your-string-to-search>" <files-to-search>
# OPTIONAL-FILTERS
# +--------+----------------------------------------------------------------------------+
# | OPTION | DESCRIPTION |
# +--------+----------------------------------------------------------------------------+
# | -e | pattern |
# | -i | Ignore uppercase vs. lowercase. |
# | -v | Invert match. |
# | -c | Output count of matching lines only. |
# | -l | Output matching files only. |
# | -n | Precede each matching line with a line number. |
# | -b | A historical curiosity: precede each matching line with a block number. |
# | -h | Output matching lines without preceding them by file names. |
# | -s | Suppress error messages about nonexistent or unreadable files. |
# | -x | |
# | -f | file: Take regexes from a file. |
# | -o | Output the matched parts of a matching line. |
# +--------+----------------------------------------------------------------------------+