

{"id":108800,"date":"2022-05-26T09:00:20","date_gmt":"2022-05-26T03:30:20","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=108800"},"modified":"2022-05-26T10:47:34","modified_gmt":"2022-05-26T05:17:34","slug":"grep-command-in-linux","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/grep-command-in-linux\/","title":{"rendered":"Grep Command in Linux"},"content":{"rendered":"<p>In this document, you will learn how to use the grep command in Linux and why it is used. Go through most of the options that are used with grep command to search better, and also how to combine 2 or more commands, so that you can optimize and improve your searching techniques using the Grep command.<\/p>\n<h3>What is Grep command?<\/h3>\n<p>Grep command is a LINUX command which stands for Global regular expression print. The Grep command is used to search a file(s) for a word(s), sentence(s) or any pattern of words or characters and displays all the lines that contain the same.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep &lt;options&gt; \u201cword\/sentence\u201d&lt;file(s)&gt;<\/pre>\n<p>The syntax is pretty easy to understand: for the grep command we use any predefined options (which we will look into later) for more concise outputs. Then enter the word(s) or sentence(s) you want to search and the file(s) you want to search in.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>grep \u201cferrari\u201d car.txt<\/p>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">\n<p><strong>ferrari<\/strong> is a sports car manufacture<strong>ferrari<\/strong> SP3 monza is their latest halo car<\/p>\n<p><strong>ferrari<\/strong><\/p>\n<p>Lamborghini is better than <strong>ferrari<\/strong><\/p>\n<\/div>\n<p>The grep command used above searches for the word \u2018ferrari\u2019 in the file \u2018cars.txt\u2019 and prints all the sentences in which it finds the word \u201cferrari\u201d . It prints the other outputs also (not only the 3rd output) because the word \u201cferrari\u201d is in them too.<\/p>\n<p>But what if we want to search only \u2018ferrari\u2019 or maybe even the line numbers it occurs in, or some context after and before the sentence the word is in? Well, that is why grep comes with a lot of predefined options to help us get a more accurate output. We can also combine 2 or more options to combine their functionalities and narrow down the output to exactly how we want it.<\/p>\n<p>Let us look into the options of grep command in detail.<\/p>\n<p><span style=\"font-weight: 400\">Before I go any further, let us take a standard text file to work on. For the rest of the article, I will be following the sample file cars.txt with the following content:<\/span><\/p>\n<p><span style=\"font-weight: 400\">1:\u00a0 <\/span><b>ferrari <\/b><span style=\"font-weight: 400\">is a sports car manufacture<\/span><\/p>\n<p><span style=\"font-weight: 400\">2: Enzo <\/span><b>Ferrari <\/b><span style=\"font-weight: 400\">is the founder.<\/span><\/p>\n<p><span style=\"font-weight: 400\">3: the company is in Italy<\/span><\/p>\n<p><span style=\"font-weight: 400\">4:\u00a0 <\/span><b>ferrari <\/b><span style=\"font-weight: 400\">SP3 monza is their latest halo car<\/span><\/p>\n<p><span style=\"font-weight: 400\">5: which is extremely fast<\/span><\/p>\n<p><span style=\"font-weight: 400\">6: with a 6.5L NA v12, producing 830 hp.<\/span><\/p>\n<p><span style=\"font-weight: 400\">7:\u00a0 <\/span><b>ferrari<\/b><\/p>\n<p><span style=\"font-weight: 400\">9<\/span><span style=\"font-weight: 400\">:<\/span><span style=\"font-weight: 400\"> Test words: FeRrArI, feRRari, <\/span><b>ferrARI<\/b><\/p>\n<p><span style=\"font-weight: 400\">10: The <\/span><span style=\"font-weight: 400\">458<\/span><span style=\"font-weight: 400\"> italia is my favorite car of them<\/span><\/p>\n<p><span style=\"font-weight: 400\">11: However I think,<\/span><\/p>\n<p><span style=\"font-weight: 400\">12: Lamborghini is better than <\/span><b>ferrari<\/b><\/p>\n<p><span style=\"font-weight: 400\">13: Because I like their styling<\/span><\/p>\n<p><span style=\"font-weight: 400\">14: Which is bold and striking!<\/span><\/p>\n<p><span style=\"font-weight: 400\">15: Some of their cars also have scissor doors\u00a0<\/span><\/p>\n<h3>Options used with Grep command<\/h3>\n<p><strong>a. -i<\/strong><\/p>\n<p>Grep is a case sensitive command, which means that it will give the output of the exact case of what you typed. To make grep case insensitive (i.e. to output words like Ferrari, ferrari, FeRRari, ferRAI, etc) we use the option \u2018-i\u2019.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -i \u201cword\/sentence\u201d&lt;file(s)&gt;<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -i \u201cferrari\u201d car.txt<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">\n<p><strong>ferrari<\/strong> is a sports car manufactureEnzo <strong>Ferrari<\/strong> is the founder.<\/p>\n<p><strong>ferrari<\/strong> SP3 Monza is their latest halo car<\/p>\n<p><strong>ferrari<\/strong><\/p>\n<p>Test words: <strong>FeRrArI, feRRari, ferrARI<\/strong><\/p>\n<p>Lamborghini is better than <strong>ferrari<\/strong><\/p>\n<\/div>\n<p><strong>b. -n<\/strong><\/p>\n<p>Sometimes you may want to know the line number a word or a sentence is in. For printing out the line numbers we use the option \u2018-n\u2019.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -n \u201cword\/sentence\u201d&lt;file(s)&gt;<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -n \u201cferrari\u201d car.txt<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">\n<p>1: <strong>ferrari<\/strong> is a sports car manufacture4: <strong>ferrari<\/strong> SP3 monza is their latest halo car<\/p>\n<p>7: <strong>ferrari<\/strong><\/p>\n<p>12: Lamborghini is better than <strong>ferrari<\/strong><\/p>\n<\/div>\n<p><strong>c. -o<\/strong><\/p>\n<p>Notice in the previous 2 outputs, when we were searching for a word, we not only got the whole sentence the word was in. So if we want only the word and not the sentence it is in, we use the option \u2018-o\u2019.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -o \u201cword\/sentence\u201d&lt;file(s)&gt;<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -o \u201cferrari\u201d car.txt<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">\n<p><strong>ferrari<\/strong><strong>ferrari <\/strong><\/p>\n<p><strong>ferrari<\/strong><\/p>\n<p><strong>ferrari<\/strong><\/p>\n<\/div>\n<p><strong>d. -c<\/strong><\/p>\n<p>The option -c gives us the count of the number of lines the word or sentence you have searched is in.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -c \u201cword\/sentence\u201d&lt;file(s)&gt;<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -c \u201cferrari\u201d cars.txt<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">4<\/div>\n<p>Sometimes if you are lost and want some context around the word\/sentence you want to find, you can use the next 3 options (options 5, 6 and 7):<\/p>\n<p><strong>e. -B n<\/strong><\/p>\n<p>The option \u2018-Bn&#8217; is used to give n lines before the word that you are searching (note that this option will give n lines before the word for every result or match you get).<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -B n \u201cword\/sentence\u201d&lt;file(s)&gt;<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -B 2 \u201cLamborghini\u201d cars.txt<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">\n<p>The 458 italia is my favorite car of themHowever I think,<\/p>\n<p><strong>Lamborghini<\/strong> is better than ferrari<\/p>\n<\/div>\n<p>The command gave me 2 lines before the sentence it found the word \u2018Lamborghini\u2019.<\/p>\n<p><strong>f. -A n<\/strong><\/p>\n<p>The option \u2018-An&#8217; is used to give n lines after the word that you are searching (note that this option will give n lines after the word for every result or match you get).<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -A n \u201cword\/sentence\u201d&lt;file(s)&gt;<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -A 3 \u201cLamborghini\u201d cars.txt<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">\n<p><strong>Lamborghini<\/strong> is better than ferrariBecause I like their styling<\/p>\n<p>Which is bold and striking!<\/p>\n<p>Some of their cars also have scissor doors<\/p>\n<\/div>\n<p>The command gave 3 lines after the sentence it found the word \u2018Lamborghini\u2019.<\/p>\n<p><strong>g. -C n<\/strong><\/p>\n<p>The option \u2018-Bn&#8217; is used to give n lines before and after the word that you are searching (note that this option will give n lines before the word for every result or match you get). This option is used to give a holistic picture as you get the content around your match.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -C n \u201cword\/sentence\u201d&lt;file(s)&gt;<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -c 2 \u201cLamborghini\u201d cars.txt<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">\n<p>The 458 italia is my favorite car of themHowever I think,<\/p>\n<p><strong>Lamborghini<\/strong> is better than ferrari<\/p>\n<p>Because I like their styling<\/p>\n<p>Which is bold and striking!<\/p>\n<\/div>\n<p>The command gave me 2 lines before and after the sentence it found the word \u2018Lamborghini\u2019.<\/p>\n<p><strong>h. -v<\/strong><\/p>\n<p>The option \u2018v\u2019 will print all the lines of the file which do not contain<\/p>\n<p>the word\/sentence you are searching for. It works like an invert filter.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -v \u201cword\/sentence\u201d&lt;file(s)&gt;<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -v \u201cLamborghini\u201d cars.txt<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>This command will print out the entire document of cars.txt except for the line \u2018Lamborghini is better than ferrari\u2019.<\/p>\n<p><strong>i. -w<\/strong><\/p>\n<p>This option will match the whole word you want to search.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -w \u201cword\/sentence\u201d&lt;file(s)&gt;<\/pre>\n<p>This is better understood with an example: (let me take a different example)<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>Suppose I have a document &#8216;names.txt\u2019 with the following names: James William, James Williams, James Williamson and James williamsons.<\/p>\n<p>Now If I run a regular grep command with no options:<\/p>\n<p>grep \u201cJames William\u201d names.txt<\/p>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">\n<p><strong>James William<\/strong><strong>James William<\/strong>s<\/p>\n<p><strong>James William<\/strong>son<\/p>\n<p><strong>James William<\/strong>sons<\/p>\n<\/div>\n<p>The output is given like this because there is the word \u2018James William\u2019 in all 4 names. Now this will is not an ideal method if we want to search names in a phone book or words in a dictionary, because the word we want to search might be a substring of another word (eg: <strong>bow<\/strong> and<strong> bow<\/strong>els or <strong>is<\/strong> and th<strong>is<\/strong>).<\/p>\n<p>So to avoid this mistake we use the option\u2019-w\u2019 to force the result to the exact word we want to search.<\/p>\n<p>Now If I run the same grep command with \u2018-w\u2019 option:<\/p>\n<p>grep -w \u201cJames William\u201d names.txt<\/p>\n<p>I will get the output as:<\/p>\n<div class=\"code-output\"><strong>James William<\/strong><\/div>\n<p><strong>j. -I<\/strong><\/p>\n<p>The option \u2018-I\u2019 is used to display the files in which the word\/sentence you want to search exists.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -I \u201cword\/sentence\u201d&lt;files&gt;<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<p>Let us say that the \u2018cars.txt\u2019 file has been copied in multiple files cars1.txt, cars2.txt, cars3.txt<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -I \u201cLamborghini\u201d cars.txt cars1.txt cars2.txt<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">\n<p>cars.txtcars1.txt<\/p>\n<p>cars2.txt<\/p>\n<\/div>\n<p><strong>k. fgrep \/ -F<\/strong><\/p>\n<p>The option \u2018-F\u2019 or fgrep is used to search for special character like ^ or { or ] or \u2018\u2019 or any other for that matter.<\/p>\n<p><strong>l. -E<\/strong><\/p>\n<p>The option \u2018-E\u2019 is also used to search special characters like the option\u2019-F\u2019 but you have to use \u2018\\\u2019 as an escape character before the special character.<\/p>\n<p>E.g: If you want to search : \u2018car\u2019 you can do so by:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -E \u2018\\\u2019car\\\u2019\u2019<\/pre>\n<h3>Optimizing search results by Combining options used with Grep command:<\/h3>\n<p>Now that we have seen most of the tags that go with the grep command, let us see a few examples on how we can combine 2 or more options to narrow down or give a more desirable output.<\/p>\n<h4>Example 1:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -ino \u201clamborghini\u201d cars.txt<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">12: <strong>Lamborghini<\/strong><\/div>\n<p>The \u2018-ino\u2019 is a combination of \u2018-i\u2019 option which makes the grep case insensitive which gave the output as \u2018<strong>L<\/strong>amborghini\u2019 even though I entered \u2018<strong>l<\/strong>amborghini\u2019, the \u2018-n\u2019 option gave me the line number the word was in, and the \u2018-0\u2019 option gave me only the word I wanted and not the entire sentence it is in.<\/p>\n<h4>Example 2:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep -win -A 3 \u201cJames william\u201d names.txt<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">\n<p>1: <strong>James William<\/strong>2: James Williams<\/p>\n<p>3: James Williamson<\/p>\n<p>4: James Williamsons<\/p>\n<\/div>\n<p>The \u2018-win &#8211; A 3\u2019 is a combination of \u2018-w\u2019 option which I used so that I can forcibly choose only \u2018James William\u2019 and not the other names because the others have \u2018<strong>J<\/strong>ames <strong>W<\/strong>illiam\u2019 as a subscript in them. The option \u2018-i\u2019 made the grep command case insensitive which gave the output as \u2018James William\u2019 even though I entered \u2018<strong>j<\/strong>ames <strong>w<\/strong>illiam\u2019. The \u2018-n\u2019option printed out the line number of which the word is in, and the \u2018-A 3\u2019 option gave me 3 lines after the matching result.<\/p>\n<h4>Example 3:<\/h4>\n<p>Using Grep with pipe:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">history | grep \u201cgit command\u201d<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>This command will first run the history command, which will send all the output as the input to the grep command (that is what pspie is used for, it sends the output of the first command as the input to the second command). Hen grep will search for the files with the name \u201cgit command\u201d and print them out.<\/p>\n<p>Different options can be used together to narrow down your search or simply get better results. Here are 2 more search optimization techniques similar to options:<\/p>\n<p><strong>a. ^<\/strong><\/p>\n<p>The \u2018^\u2019 is used to display all lines that begin with the word you search for.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep \u201c^word\/sentence\u201d&lt;file(s)&gt;<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep \u201c^T\u201d cars.txt<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\"><strong>T<\/strong>est words: FeRrArI, feRRari, ferrARI<\/div>\n<p><strong>b. $<\/strong><\/p>\n<p>The \u2018$\u2019 is used to display all lines that end with the word you search for.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep \u201cword\/sentence$\u201d&lt;file(s)&gt;<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep \u201cferrari$\u201d cars.txt<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Lamborghini is better than <strong>ferrari<\/strong><\/div>\n<p>If I write:<\/p>\n<p>grep -in \u201cferrari$\u201d cars.txt<\/p>\n<p>It will print:<\/p>\n<div class=\"code-output\">\n<p>9: Test words: FeRrArI, feRRari<strong>, ferrARI<\/strong><\/p>\n<p>12: Lamborghini is better than ferrari<\/p>\n<\/div>\n<p>As \u2018-i\u2019 will make grep case insensitive, and \u2018-n\u2019 give the line numbers<\/p>\n<h3>Summary<\/h3>\n<p>As you have seen the grep command is a very powerful command which helps you to quickly find different patterns of characters in a file or files. The grep command can also be combined with many other linux commands like sort, pipe and a lot more, which make work flow a lot more efficient, especially when you are working on large projects with large numbers of files.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this document, you will learn how to use the grep command in Linux and why it is used. Go through most of the options that are used with grep command to search better,&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":109278,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[26847,26849,26848],"class_list":["post-108800","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-grep-command-in-linux","tag-grep-option","tag-linux-grep"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Grep Command in Linux - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn about Grep Command in Linux. Learn to optimize search results by Combining options used with Grep command.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/grep-command-in-linux\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Grep Command in Linux - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn about Grep Command in Linux. Learn to optimize search results by Combining options used with Grep command.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/grep-command-in-linux\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-05-26T03:30:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-05-26T05:17:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/04\/grep-command-in-linux.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Grep Command in Linux - DataFlair","description":"Learn about Grep Command in Linux. Learn to optimize search results by Combining options used with Grep command.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/grep-command-in-linux\/","og_locale":"en_US","og_type":"article","og_title":"Grep Command in Linux - DataFlair","og_description":"Learn about Grep Command in Linux. Learn to optimize search results by Combining options used with Grep command.","og_url":"https:\/\/data-flair.training\/blogs\/grep-command-in-linux\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2022-05-26T03:30:20+00:00","article_modified_time":"2022-05-26T05:17:34+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/04\/grep-command-in-linux.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/grep-command-in-linux\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/grep-command-in-linux\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/b49855299264df5e27e3ec6c2cd9fde9"},"headline":"Grep Command in Linux","datePublished":"2022-05-26T03:30:20+00:00","dateModified":"2022-05-26T05:17:34+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/grep-command-in-linux\/"},"wordCount":1689,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/grep-command-in-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/04\/grep-command-in-linux.webp","keywords":["GREP Command in Linux","Grep Option","Linux Grep"],"articleSection":["Linux Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/grep-command-in-linux\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/grep-command-in-linux\/","url":"https:\/\/data-flair.training\/blogs\/grep-command-in-linux\/","name":"Grep Command in Linux - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/grep-command-in-linux\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/grep-command-in-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/04\/grep-command-in-linux.webp","datePublished":"2022-05-26T03:30:20+00:00","dateModified":"2022-05-26T05:17:34+00:00","description":"Learn about Grep Command in Linux. Learn to optimize search results by Combining options used with Grep command.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/grep-command-in-linux\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/grep-command-in-linux\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/grep-command-in-linux\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/04\/grep-command-in-linux.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/04\/grep-command-in-linux.webp","width":1200,"height":628,"caption":"grep command in linux"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/grep-command-in-linux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Linux Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/linux\/"},{"@type":"ListItem","position":3,"name":"Grep Command in Linux"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/b49855299264df5e27e3ec6c2cd9fde9","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/ef46b745ddad2fad690af626c6ef29b91809ad0a9f5ef398d07817d8cad042f5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/ef46b745ddad2fad690af626c6ef29b91809ad0a9f5ef398d07817d8cad042f5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ef46b745ddad2fad690af626c6ef29b91809ad0a9f5ef398d07817d8cad042f5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team is a group of passionate educators and industry experts dedicated to providing high-quality online learning resources on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. With years of experience in the field, the team aims to simplify complex topics and help learners advance their careers. At DataFlair, we believe in empowering students and professionals with the knowledge and skills needed to thrive in today\u2019s fast-paced tech industry. Follow us for Free courses, expert insights, tutorials, and practical tips to boost your learning journey.","url":"https:\/\/data-flair.training\/blogs\/author\/datafbdad\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/108800","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=108800"}],"version-history":[{"count":9,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/108800\/revisions"}],"predecessor-version":[{"id":109292,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/108800\/revisions\/109292"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/109278"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=108800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=108800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=108800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}