Unix : Search for a regular expression in a directory

The widely used and familiar command 'grep' can be used to search for a regular expression and print it.
There are numerous options available with grep', today we learn how to search for a regular expression / text in a directory. The approach is straightforward and self explanatory.
The syntax can be generalized as follows

grep 'text' *

The above command searches for the pattern 'text' in all the files in the current directory.
For example , if you want to search the occurrence of the pattern text 'compiler' in all files in the current directory, the approach is as follows..

grep 'compiler' *

Stay tuned, the following posts describe in detail the various options available with 'grep'.
As the great Tao of Programming says, grep sed and awk are in themselves a league of programming language.

You may also want to read how to search for a String in files of all sub-directories

No comments :

Post a Comment