What is the use of ‘grep’ command? Provide an exampleGrep stands for regular expression. ‘grep’ command is used to find the patterns in a text file provided by the user. It returns true if the pattern is found in the file, otherwise false.
Examples:
grep Lin file1 file2 file3 searches the files file1, file2, file3 for the lines which contains the string Lin.
grep ‘Linux learning is great ’ file1 file2 file3 searches the files file1, file2, file3 for the lines which contains the string ‘Linux learning is great’.
grep -c Linux operatinsystems displays only the number of times that the pattern is matched in the file but not the lines.
grep -r 'Linus Torvalds' * searches for the files in current and all the sub directories for the pattern (Linus Torvalds).
|