Note -r searches recursively through directories. -n shows line numbers. -i is case-insensitive. -v inverts the match (shows non-matching lines). -c counts matches. -l lists only filenames with matches. Use -E for extended regex or egrep.
Note Returns the 1-based position of the first occurrence. Returns 0 if not found (not -1 like most programming languages). MySQL uses LOCATE(substring, string) which has the arguments in reverse order.
Frequently asked questions
How do you find in string?
This task is covered in 3 stacks on this page: Bash & Linux, JavaScript, SQL. The "Search Text with Patterns" snippet in Bash & Linux uses `grep [options] pattern [file...]`.
Which command does the Bash & Linux example use?
The "Search Text with Patterns" snippet uses `grep [options] pattern [file...]`, from the Text Processing section of the Bash & Linux cheat sheet.
Which stacks cover "find in string" on this page?
Bash & Linux, JavaScript, SQL. Together they hold 3 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "Search Text with Patterns": -r searches recursively through directories. -n shows line numbers. -i is case-insensitive. -v inverts the match (shows non-matching lines). -c counts matches. -l lists only filenames with matches. Use -E for extended regex or egrep.