# 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. |
# +--------+----------------------------------------------------------------------------+
# It can be done in two ways
# 1) Have "grep" read on from the standard input using a pipe
# and search the input string. Then pipe the result to "wc" to count
# the number of occurences
$ line="This is where we select from a table."
# substr="select"
$ echo "$line" | grep "$substr" | wc -l
# 2) or pass a string to "grep" and search the string for a substring
# pass the result to "wc" to count the number of occurence
$ grep "$substr" <<< "$line" | wc -l
# 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. |
# +--------+----------------------------------------------------------------------------+
# It can be done in two ways
# 1) Have "grep" read on from the standard input using a pipe
# and search the input string. Then pipe the result to "wc" to count
# the number of occurences
$ line="This is where we select from a table."
# substr="select"
$ echo "$line" | grep "$substr" | wc -l
# 2) or pass a string to "grep" and search the string for a substring
# pass the result to "wc" to count the number of occurence
$ grep "$substr" <<< "$line" | wc -l