grep get matched text's filename and line number in bash
bash, grep
Solution
grep -nrH 'regex' /dir/
`-H` is the option that adds filenames, `-n` adds line numbers, `-r` is recursive
I get filenames even without the `-H` unless there's only one file.
Add `-i` for case-insensitive
Add `-E` for extended regular expressions
Problem
I want to do a `grep` in bash on a folder searching for the term `foobar`. I then want to output all of the matches along w/ the filename and line number where the occurrences were found. Is this possible? I need the output to look like: ``` {{filename}}:{{line_number}} - {{matched_text}} ```