By default, grep displays the lines in one or more files that match your search string (or regular expression). Here is how you recursively search through a directory of files and list the name(s) of the files that contain a matching string instead of the matched line.
The -l switch indicates that you want to display the names of files that contain a string that matches your query. Here is an example of its use with an entire directory of xml files (using the *.xml wildcard):
This command causes grep to search for lines that match the query SEARCH_TERM in every .xml file in the given directory & will print the names of the files that contain a match to the standard output stream.
Replace SEARCH_TERM with your query and *.xml with any filetype or the name pattern of a set of files that you would like to search. The query can be a string or regular expression.
grep -l Switch
The -l switch indicates that you want to display the names of files that contain a string that matches your query. Here is an example of its use with an entire directory of xml files (using the *.xml wildcard):
grep -l 'SEARCH_TERM' /path_to_your_directory/*.xml
This command causes grep to search for lines that match the query SEARCH_TERM in every .xml file in the given directory & will print the names of the files that contain a match to the standard output stream.
abc.xml
another_abc.xml
Replace SEARCH_TERM with your query and *.xml with any filetype or the name pattern of a set of files that you would like to search. The query can be a string or regular expression.
You can find grep documentation here
No comments:
Post a Comment