Yes, grep can count lines and occurrence of the specific pattern inside the target file. To achieve the result you have to use the syntax: count=$(grep -c "$search_line" "$file_to_search")