{"id":386,"date":"2026-01-15T04:15:43","date_gmt":"2026-01-15T04:15:43","guid":{"rendered":"https:\/\/mitalgoswami.in\/?p=386"},"modified":"2026-01-28T04:36:42","modified_gmt":"2026-01-28T04:36:42","slug":"what-are-grep-fgrep-egreppattern-matching-command","status":"publish","type":"post","link":"https:\/\/mitalgoswami.in\/?p=386","title":{"rendered":"What are grep, fgrep, egrep?[Pattern Matching Command]"},"content":{"rendered":"\n<p>What are grep, fgrep, egrep?<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1&#xfe0f;&#x20e3; <code>grep<\/code> \u2013 General Pattern Search (Basic Regular Expressions)<\/h2>\n\n\n\n<p>1)grep command:-(global regular expression print)<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Uses <strong>Basic Regular Expressions (BRE)<\/strong><\/li>\n\n\n\n<li>Most commonly used command<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Syntax<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>grep \"pattern\" file_name\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Example<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>grep \"unix\" notes.txt\ngrep \"m\" a.txt\ngrep \"M\" a.txt\ngrep -i \"M\"  a.txt  #case insensitive\ngrep -c \"M\" a.txt  #line count\ngrep -n \"M\" a.txt #line number\ngrep -w \"MM\" a.txt # word \n\ngrep -f a.txt b.txt #mathching of two file\ngrep -L \"unix\" * #file names that matches &amp; pattern\n\n<\/code><\/pre>\n\n\n\n<p>&#x1f539; Searches lines containing <strong>unix<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Using regex<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>grep \"^u\" notes.txt\n<\/code><\/pre>\n\n\n\n<p>&#x1f539; Lines starting with <code>u<\/code><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">2&#xfe0f;&#x20e3; <code>fgrep<\/code> \u2013 Fixed String Search (Fast &amp; Simple)<\/h2>\n\n\n\n<p>2)fgrep command:-fixed-character strings in a file<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>No regular expressions<\/strong><\/li>\n\n\n\n<li>Searches <strong>exact words or strings<\/strong><\/li>\n\n\n\n<li>Faster for plain text<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Syntax<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>fgrep \"pattern\" file_name\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Example<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>fgrep \"unix|linux\" notes.txt\nfgrep \"mm\" a.txt\nfgrep -c \"m\" a.txt #line number\nfgrep \"m\" *.txt\nfgrep -l \"@a\" a.txt #print filename\nfgrep -n \"@a\" a.txt #print line number\nfgrep -x \"a\" a.txt   #display only lines matched entirely.\n<\/code><\/pre>\n\n\n\n<p>&#x1f539; Searches the <strong>exact text<\/strong> <code>unix|linux<\/code><br>(Not OR condition)<\/p>\n\n\n\n<p>&#x2705; Best when:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You don\u2019t want regex<\/li>\n\n\n\n<li>You want speed<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3&#xfe0f;&#x20e3; <code>egrep<\/code> \u2013 Extended Regular Expressions<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Uses <strong>Extended Regular Expressions (ERE)<\/strong><\/li>\n\n\n\n<li>Supports <code>|<\/code>, <code>+<\/code>, <code>?<\/code>, <code>()<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Syntax<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>egrep \"pattern\" file_name\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Example<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>egrep \"unix|linux\" notes.txt\negrep \"mital\"  *    #globally search\negrep \"m\" a.txt\negrep -c \"mm\" a.txt   #linenumber mathched\negrep -l \"mm\" a.txt  # print filename\negrep -n \"mm\" a.txt # print linenumber\negrep -r \"m*\" m.txt\negrep -r \"m*\" .     #recursively searching whole root\n<\/code><\/pre>\n\n\n\n<p>&#x1f539; Matches <strong>unix OR linux<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>egrep \"(cat|dog)s?\" animals.txt\n<\/code><\/pre>\n\n\n\n<p>&#x1f539; Matches <code>cat<\/code>, <code>cats<\/code>, <code>dog<\/code>, <code>dogs<\/code><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">&#x1f501; Key Differences (Very Important for Exams)<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Feature<\/th><th>grep<\/th><th>fgrep<\/th><th>egrep<\/th><\/tr><\/thead><tbody><tr><td>Pattern type<\/td><td>Basic Regex<\/td><td>Fixed string<\/td><td>Extended Regex<\/td><\/tr><tr><td>Supports `<\/td><td>` (OR)<\/td><td>&#x274c;<\/td><td>&#x274c;<\/td><\/tr><tr><td>Supports <code>+<\/code>, <code>?<\/code>, <code>()<\/code><\/td><td>&#x274c;<\/td><td>&#x274c;<\/td><td>&#x2705;<\/td><\/tr><tr><td>Fastest<\/td><td>&#x274c;<\/td><td>&#x2705;<\/td><td>&#x274c;<\/td><\/tr><tr><td>Most flexible<\/td><td>&#x274c;<\/td><td>&#x274c;<\/td><td>&#x2705;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">&#x26a0;&#xfe0f; Important Note (Modern UNIX\/Linux)<\/h2>\n\n\n\n<p>Today:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>fgrep<\/code> = <code>grep -F<\/code><\/li>\n\n\n\n<li><code>egrep<\/code> = <code>grep -E<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Examples<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -F \"unix|linux\" file.txt\ngrep -E \"unix|linux\" file.txt\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">&#x1f4dd; Easy Memory Trick<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>grep<\/strong> \u2192 basic search<\/li>\n\n\n\n<li><strong>fgrep<\/strong> \u2192 fixed text (no regex)<\/li>\n\n\n\n<li><strong>egrep<\/strong> \u2192 extra power (OR, +, ?)<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>What are grep, fgrep, egrep? 1&#xfe0f;&#x20e3; grep \u2013 General Pattern Search (Basic Regular Expressions) 1)grep command:-(global regular expression print) Syntax Example &#x1f539; Searches lines containing unix Using regex &#x1f539; Lines starting with u 2&#xfe0f;&#x20e3; fgrep \u2013 Fixed String Search (Fast &amp; Simple) 2)fgrep command:-fixed-character strings in a file Syntax Example &#x1f539; Searches the exact text [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-386","post","type-post","status-publish","format-standard","hentry","category-unix"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/386","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=386"}],"version-history":[{"count":1,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/386\/revisions"}],"predecessor-version":[{"id":387,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/386\/revisions\/387"}],"wp:attachment":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=386"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}