![]() -o, -only-matching - display only the matching part, instead of displaying the entire line.-m, -max-count - stop the search after the specified number of lines is found.-l, -files-with-match - similar to the previous one, but only files with at least one match will be displayed.-L, -files-without-match - display only file names, all files where the search is performed will be displayed.-color - enable color mode, available values: never, always, and auto.-c - display the number of lines found.-x, -line-regexp - search for the pattern as an entire line, from the beginning to the newline character.-w, -word-regexp - search for the pattern as a word separated by spaces or other punctuation marks.-v, -invert-match - display only those lines in which not match with search pattern.-i, -ignore-case - ignore character case.-f, -file - read the search pattern from a file.-e, -regexp - an alternative way to specify the search pattern, the option can be used multiple times, which allows specifying multiple patterns for searching files containing one of them.-P, -perl-regexp - interpret the search pattern as a Perl regular expression.-G, -basic-regexp - interpret the search pattern as a basic regular expression (BRE).-F, -fixed-strings - use the search pattern as a string, not a regular expression.-E, -extended-regexp - enable extended regular expression mode (ERE).Let's have a look at the most used options of the command which can help you to search text in files more efficiently: The ability to filter standard output can be helpful when you need to select only lines with errors from logs or filter only the necessary information from the output of some other command. As you will see later, grep allows searching in multiple files and even in a directory using recursive mode. /path/to/the/file/or/directory are the locations where the search will be performed.P attern is a regular expression or string that the search will be performed on.Options are additional parameters that specify various search and output settings, such as the number of lines or inversion mode.The grep command has the following syntax: The utility is very popular because it is pre-installed in almost all distributions. You can select necessary lines from text files, filter output of other commands, and even search for files in the filesystem, which contain specific words. The command has pretty much possibilities for text filtering. Later, a free utility with the same functionality was developed within the GNU project. Before the GNU project was created, there was a precursor utility named grep too, which was developed in 1973 by Ken Thompson for searching files by content in Unix. It is one of the most in-demand commands in the Linux terminal and is part of GNU project. The name of this command stands for "search globally for lines matching the regular expression, and print them".
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |