You can search within a file using the grep command. Here’s how to do it:
-
Basic Search:
grep "search_term" filename.txtThis command searches for the specified
search_terminfilename.txtand displays the matching lines. -
Case-Insensitive Search:
grep -i "search_term" filename.txtThis command performs a case-insensitive search.
-
Search for Whole Words:
grep -w "search_term" filename.txtThis command searches for the whole word only.
-
Display Line Numbers:
grep -n "search_term" filename.txtThis command shows the line numbers of the matching lines.
-
Search Recursively in Directories:
grep -r "search_term" /path/to/directoryThis command searches for the term in all files within the specified directory and its subdirectories.
You can combine these options as needed. For example:
grep -i -n "search_term" filename.txt
This command performs a case-insensitive search and displays line numbers.
