
For instance, consider that you need to search for the pattern “Linux” in the file sampleTextFile.txt, then you would have to use the command below:Īt the output, you will only get the exact pattern, i.e. If you only want to get only the matched pattern within a file, you need to pass the -o flag in the grep command. In the output, you will get the number of exact matches of the pattern found in the file, which is 2 in this case:ģ. To do that, you will have to use the following command: Now, you may need to find the number of matches for the word “Linux” in the same file i.e. Get the number of matches for a pattern in a file So, what you need to do is to run the following command in the terminal:Īt the output, you will be able to see the name of the file that contains the pattern:Ģ. Get the name of files that contains a specific pattern (string)Īssume that you want to know which files have the pattern or word “Linux” in it. To develop a better understanding of the Grep command, here are some examples that you should take a look at: 1. In the output, you will be able to see all the lines that have the word Linux in them, just keep a note that no consideration will be given to the casing due to the -i flag. This means that the search term is case insensitive. This command basically means that grep will need to find the word Linux in the file named sampleTextFile.txt.

It’s quite easy to make use of the grep command in your Linux- or UNIX-based system.
#GREP SYNTAX HOW TO#
How to Use GREP Command in UNIX/Linux Terminals


What is the grep meaning? The GREP stands for Global Expression Regular Print, which is used in Linux/Unix terminals as grep. What is the grep Command and what it can do for you? If you wish to develop using Linux then you should definitely know about it. To cut the chase, the Linux grep command is a very important command that is basic yet powerful. There are several commands that it supports, among which some are essential. Linux is a develop(ment)er-friendly operating system. Primary Benefits of Using the grep Command List of content you will read in this article:
