Linux grep command
The Linux grep command stands for “Global Regular Expression Print“. The grep command-line utility is used for searching content from files based on a pattern or regular expression.
Syntax:
Example:
Search all users under /etc/passwd have the bash shell.
Grep command can also take the output of another command as input using pipes. For example:
Case Sensitive Search
Grep uses -i option to run a case-sensitive search.
Search Recursively in Directory Tree
Using the -r switch grep to search for patterns recursively for all files under the specified directory and their subdirectories.
Print Matching Filename Only
The default grep prints the matching content on the output with the respective file names. You can hide the content and display only the filename in grep output.
Use -l to print pattern matching filenames.
Use -L to revert the output. This will print only those files where no match was found.
Print Before/After Lines of Matching Pattern
This is a useful feature of the grep command. You can print the defined number of lines just before the line matches the pattern or just after the lines of the match pattern.
Use -A followed by a number of lines to print lines before the matching pattern line.
Use -B followed by a number of lines to print lines after the matching pattern line.
Use -C followed by a number of lines to print lines before and after the matching pattern line.
0 Comments
CAN FEEDBACK
Emoji