{"id":5932,"date":"2023-07-12T23:38:36","date_gmt":"2023-07-12T23:38:36","guid":{"rendered":"https:\/\/www.webhi.com\/how-to\/?p=5932"},"modified":"2023-07-12T23:38:45","modified_gmt":"2023-07-12T23:38:45","slug":"text-pattern-search-linux-grep-regular-expressions","status":"publish","type":"post","link":"https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/","title":{"rendered":"Text Pattern Search in Linux with Grep &#038; Regular Expressions"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2023\/06\/grep_regex_en.jpg\" alt=\"Using Grep &amp; Regular Expressions to Search for Text Patterns in Linux\" class=\"wp-image-5947\" srcset=\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2023\/06\/grep_regex_en.jpg 1200w, https:\/\/www.webhi.com\/how-to\/gilrogre\/2023\/06\/grep_regex_en-300x169.jpg 300w, https:\/\/www.webhi.com\/how-to\/gilrogre\/2023\/06\/grep_regex_en-1024x576.jpg 1024w, https:\/\/www.webhi.com\/how-to\/gilrogre\/2023\/06\/grep_regex_en-768x432.jpg 768w, https:\/\/www.webhi.com\/how-to\/gilrogre\/2023\/06\/grep_regex_en-150x84.jpg 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<p>When it comes to searching for specific text patterns in Linux, two powerful tools come to mind:\u00a0<strong><code>grep<\/code>\u00a0and regular expressions<\/strong>. Combining the functionality of\u00a0<code>grep<\/code>\u00a0with the flexibility of regular expressions allows users to efficiently search through files and directories, pinpointing relevant information with ease. In this article, we will explore the basics of using\u00a0<code>grep<\/code>\u00a0and regular expressions in Linux and demonstrate how they can be leveraged for effective text pattern searching.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-grep\">What is Grep?<\/h2>\n\n\n\n<p>&#8220;<code>grep\"<\/code>\u00a0stands for &#8220;Global Regular Expression Print.&#8221; It is a command-line tool that allows users to search for specific text patterns within files or input streams. It is widely used in Linux and other Unix-like operating systems due to its simplicity and powerful search capabilities.<\/p>\n\n\n\n<p>The basic syntax of&nbsp;<code>grep<\/code>&nbsp;is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ grep [options] pattern [file...]<\/code><\/pre>\n\n\n\n<p>Here,&nbsp;<code>pattern<\/code>&nbsp;represents the regular expression pattern you want to search for, and&nbsp;<code>file<\/code>&nbsp;refers to the file or files in which you want to search. If no file is specified,&nbsp;<code>grep<\/code>&nbsp;will read from the standard input.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"understanding-regular-expressions\">Understanding Regular Expressions<\/h2>\n\n\n\n<p>Regular expressions (regex) are a sequence of characters that define a search pattern. They are incredibly versatile and can be used to match specific strings, patterns, or even complex criteria within a given text. Regular expressions consist of normal characters (such as letters and digits) and special characters (such as wildcards and quantifiers) that give them their powerful search capabilities.<\/p>\n\n\n\n<p>For example, the regular expression&nbsp;<code>^Hello<\/code>&nbsp;will match any line in a file that starts with the word &#8220;Hello.&#8221; Similarly, the pattern&nbsp;<code>([A-Za-z]+)@([A-Za-z]+)\\.com<\/code>&nbsp;will match any email address in the format &#8220;<a href=\"mailto:name@example.com\">name@example.com<\/a>.&#8221;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"basic-usage-of-grep-and-regular-expressions\">Basic Usage of Grep and Regular Expressions<\/h2>\n\n\n\n<p>Let&#8217;s dive into some practical examples to understand how&nbsp;<code>grep<\/code>&nbsp;and regular expressions work together.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"searching-for-a-specific-word-in-a-file\">Searching for a specific word in a file<\/h3>\n\n\n\n<p>To search for a specific word in a file, you can use&nbsp;<code>grep<\/code>&nbsp;with a basic regular expression. For example, to find all occurrences of the word &#8220;Linux&#8221; in a file named&nbsp;<code>example.txt<\/code>, you would run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ grep \"Linux\" example.txt<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ignoring-case-sensitivity\">Ignoring case sensitivity<\/h3>\n\n\n\n<p>By default,&nbsp;<code>grep<\/code>&nbsp;is case sensitive. However, you can make it case insensitive using the&nbsp;<code>-i<\/code>&nbsp;option. For instance, to search for the word &#8220;linux&#8221; in a case-insensitive manner, you would use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ grep -i \"linux\" example.txt<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"searching-recursively-in-directories\">Searching recursively in directories<\/h3>\n\n\n\n<p><code>grep<\/code>&nbsp;also allows you to search for patterns recursively within directories. By using the&nbsp;<code>-r<\/code>&nbsp;option, you can instruct&nbsp;<code>grep<\/code>&nbsp;to search for the given pattern in all files contained within a directory and its subdirectories. Here&#8217;s an example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ grep -r \"pattern\" \/path\/to\/directory<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"displaying-line-numbers\">Displaying line numbers<\/h3>\n\n\n\n<p>If you want to display line numbers along with the matched lines, you can use the&nbsp;<code>-n<\/code>&nbsp;option. This is particularly useful when dealing with large files, as it helps you quickly locate the occurrences of a specific pattern. Here&#8217;s an example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ grep -n \"pattern\" example.txt<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"using-regular-expressions\">Using regular expressions<\/h3>\n\n\n\n<p>To unleash the full power of&nbsp;<code>grep<\/code>, you can utilize regular expressions to search for complex patterns. Regular expressions provide a wide range of special characters and operators that allow you to define intricate search criteria.<\/p>\n\n\n\n<p>For instance, to search for all lines containing numbers in a file, you can use the regular expression&nbsp;<code>[0-9]<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ grep \"[0-9]\" example.txt<\/code><\/pre>\n\n\n\n<p>Similarly, to search for lines starting with a specific pattern, you can use the caret (<code>^<\/code>) symbol. For example, the following command will match lines that start with &#8220;Hello&#8221;:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ grep \"^Hello\" example.txt<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"advanced-regular-expression-examples\">Advanced regular expression examples<\/h2>\n\n\n\n<p>Regular expressions offer various advanced features that enhance the search capabilities of&nbsp;<code>grep<\/code>. Here are a few examples:<\/p>\n\n\n\n<ul>\n<li>Matching multiple characters: You can use the dot (<code>.<\/code>) wildcard to match any single character. For example, the regular expression&nbsp;<code>b.t<\/code>&nbsp;will match &#8220;bat,&#8221; &#8220;bet,&#8221; &#8220;bit,&#8221; and so on.<\/li>\n\n\n\n<li>Quantifiers: You can use quantifiers to specify the number of occurrences of a character or group. For example,&nbsp;<code>ba*t<\/code>&nbsp;will match &#8220;bt,&#8221; &#8220;bat,&#8221; &#8220;baat,&#8221; and so on.<\/li>\n\n\n\n<li>Character classes: Square brackets (<code>[]<\/code>) allow you to define a character class. For example,&nbsp;<code>[aeiou]<\/code>&nbsp;will match any vowel, and&nbsp;<code>[0-9]<\/code>&nbsp;will match any digit.<\/li>\n<\/ul>\n\n\n\n<p>Certainly! Here are a few additional steps you can include when using&nbsp;<code>grep<\/code>&nbsp;and regular expressions to search for text patterns in Linux:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"use-anchors-for-precise-matching\">Use anchors for precise matching<\/h3>\n\n\n\n<p>Anchors are special characters that allow you to specify where in a line a pattern should match. The caret (<code>^<\/code>) anchor denotes the start of a line, and the dollar sign (<code>$<\/code>) anchor denotes the end of a line. By using anchors, you can ensure that your pattern matches precisely where you want it to.<\/p>\n\n\n\n<p>For example, to find lines that end with the word &#8220;Linux&#8221; in a file, you can use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ grep \"Linux$\" example.txt<\/code><\/pre>\n\n\n\n<p>Similarly, to search for lines that start with &#8220;Hello&#8221; and end with &#8220;world&#8221;, you can use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ grep \"^Hello.*world$\" example.txt<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"exclude-patterns-from-the-search\">Exclude patterns from the search<\/h3>\n\n\n\n<p>Sometimes you may want to exclude certain patterns from your search results.&nbsp;<code>grep<\/code>&nbsp;provides the&nbsp;<code>-v<\/code>&nbsp;option to invert the match and display lines that do not match the given pattern.<\/p>\n\n\n\n<p>For example, to search for lines in a file that do not contain the word &#8220;error,&#8221; you can use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ grep -v \"error\" example.txt<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"search-for-whole-words-only\">Search for whole words only<\/h3>\n\n\n\n<p>By default,&nbsp;<code>grep<\/code>&nbsp;matches patterns that are part of a larger word. If you want to search for whole words only, you can use the&nbsp;<code>-w<\/code>&nbsp;option. This ensures that the pattern matches as a complete word and not as part of another word.<\/p>\n\n\n\n<p>For example, to find lines that contain the word &#8220;Linux&#8221; as a whole word, you can use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ grep -w \"Linux\" example.txt<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"search-for-patterns-in-specific-file-types\">Search for patterns in specific file types<\/h3>\n\n\n\n<p>If you want to search for patterns in specific types of files, you can use the&nbsp;<code>--include<\/code>&nbsp;or&nbsp;<code>--exclude<\/code>&nbsp;options to specify file patterns. This allows you to narrow down your search to specific file types, saving time and effort.<\/p>\n\n\n\n<p>For example, to search for a pattern in all text files within a directory, you can use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ grep \"pattern\" --include \"*.txt\" \/path\/to\/directory<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"save-search-results-to-a-file\">Save search results to a file<\/h3>\n\n\n\n<p>To save the search results to a file for further analysis or reference, you can redirect the output of&nbsp;<code>grep<\/code>&nbsp;to a file using the&nbsp;<code>&gt;<\/code>&nbsp;operator.<\/p>\n\n\n\n<p>For example, to save all lines containing the word &#8220;Linux&#8221; in a file named&nbsp;<code>results.txt<\/code>, you can use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ grep \"Linux\" example.txt &gt; results.txt<\/code><\/pre>\n\n\n\n<p>Now, the matching lines will be stored in the&nbsp;<code>results.txt<\/code>&nbsp;file.<\/p>\n\n\n\n<p>These additional steps expand the functionality of&nbsp;<code>grep<\/code>&nbsp;and allow you to perform more specific and targeted searches based on your requirements. Experimenting with different options and regular expressions will help you become proficient in searching for text patterns in Linux.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>The combination of&nbsp;<code>grep<\/code>&nbsp;and regular expressions provides a powerful mechanism for searching and matching text patterns in Linux. By leveraging the flexibility and expressiveness of regular expressions, users can perform intricate searches, saving time and effort.<\/p>\n\n\n\n<p>In this article, we covered the basics of&nbsp;<code>grep<\/code>&nbsp;and regular expressions, including their syntax and common options. We explored various examples to demonstrate how&nbsp;<code>grep<\/code>&nbsp;can be used to search for specific words, patterns, and complex criteria. Regular expressions offer a vast array of possibilities, allowing users to adapt their searches to specific requirements.<\/p>\n\n\n\n<p>By mastering&nbsp;<code>grep<\/code>&nbsp;and regular expressions, you can become proficient in searching for text patterns in Linux, improving your productivity and efficiency when working with files and directories.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When it comes to searching for specific text patterns in Linux, two powerful tools come to mind:\u00a0grep\u00a0and regular expressions. Combining the functionality of\u00a0grep\u00a0with the flexibility of regular expressions allows users to efficiently search through files and directories, pinpointing relevant information with ease. In this article, we will explore the basics of using\u00a0grep\u00a0and regular expressions in ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[69],"tags":[],"yoast_head":"\n<title>Text Pattern Search in Linux with Grep &amp; Regular Expressions - WebHi Tutorials &amp; Documentations<\/title>\n<meta name=\"description\" content=\"Discover the power of using Grep and regular expressions in Linux to efficiently search for text patterns. Learn the basics, advanced techniques, and practical examples for accurate and targeted searches in this comprehensive guide.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Text Pattern Search in Linux with Grep &amp; Regular Expressions - WebHi Tutorials &amp; Documentations\" \/>\n<meta property=\"og:description\" content=\"Discover the power of using Grep and regular expressions in Linux to efficiently search for text patterns. Learn the basics, advanced techniques, and practical examples for accurate and targeted searches in this comprehensive guide.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/\" \/>\n<meta property=\"og:site_name\" content=\"WebHi Tutorials &amp; Documentations\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webhi.technology\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-12T23:38:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-12T23:38:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2023\/06\/grep_regex_en.jpg\" \/>\n<meta name=\"author\" content=\"webhi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@WebHiTechnology\" \/>\n<meta name=\"twitter:site\" content=\"@WebHiTechnology\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"webhi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/\"},\"author\":{\"name\":\"webhi\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/b31e76e2311cdc0bb90f5e2733059a54\"},\"headline\":\"Text Pattern Search in Linux with Grep &#038; Regular Expressions\",\"datePublished\":\"2023-07-12T23:38:36+00:00\",\"dateModified\":\"2023-07-12T23:38:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/\"},\"wordCount\":1225,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/#organization\"},\"articleSection\":[\"Linux system administration\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/\",\"url\":\"https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/\",\"name\":\"Text Pattern Search in Linux with Grep & Regular Expressions - WebHi Tutorials &amp; Documentations\",\"isPartOf\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/#website\"},\"datePublished\":\"2023-07-12T23:38:36+00:00\",\"dateModified\":\"2023-07-12T23:38:45+00:00\",\"description\":\"Discover the power of using Grep and regular expressions in Linux to efficiently search for text patterns. Learn the basics, advanced techniques, and practical examples for accurate and targeted searches in this comprehensive guide.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webhi.com\/how-to\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Text Pattern Search in Linux with Grep &#038; Regular Expressions\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#website\",\"url\":\"https:\/\/www.webhi.com\/how-to\/\",\"name\":\"WebHi Tutorials &amp; Documentations\",\"description\":\"System administration and knowledge base\",\"publisher\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webhi.com\/how-to\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#organization\",\"name\":\"WebHi Technology\",\"url\":\"https:\/\/www.webhi.com\/how-to\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2022\/07\/logo.png\",\"contentUrl\":\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2022\/07\/logo.png\",\"width\":288,\"height\":95,\"caption\":\"WebHi Technology\"},\"image\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webhi.technology\",\"https:\/\/twitter.com\/WebHiTechnology\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/b31e76e2311cdc0bb90f5e2733059a54\",\"name\":\"webhi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.webhi.com\/how-to\/ahuphiph\/litespeed\/avatar\/e20da107d0f4c765ead2eef88ad019d8.jpg?ver=1781214743\",\"contentUrl\":\"https:\/\/www.webhi.com\/how-to\/ahuphiph\/litespeed\/avatar\/e20da107d0f4c765ead2eef88ad019d8.jpg?ver=1781214743\",\"caption\":\"webhi\"},\"sameAs\":[\"https:\/\/www.webhi.com\/how-to\"],\"url\":\"https:\/\/www.webhi.com\/how-to\/author\/webhi\/\"}]}<\/script>\n","yoast_head_json":{"title":"Text Pattern Search in Linux with Grep & Regular Expressions - WebHi Tutorials &amp; Documentations","description":"Discover the power of using Grep and regular expressions in Linux to efficiently search for text patterns. Learn the basics, advanced techniques, and practical examples for accurate and targeted searches in this comprehensive guide.","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:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/","og_locale":"en_US","og_type":"article","og_title":"Text Pattern Search in Linux with Grep & Regular Expressions - WebHi Tutorials &amp; Documentations","og_description":"Discover the power of using Grep and regular expressions in Linux to efficiently search for text patterns. Learn the basics, advanced techniques, and practical examples for accurate and targeted searches in this comprehensive guide.","og_url":"https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/","og_site_name":"WebHi Tutorials &amp; Documentations","article_publisher":"https:\/\/www.facebook.com\/webhi.technology","article_published_time":"2023-07-12T23:38:36+00:00","article_modified_time":"2023-07-12T23:38:45+00:00","og_image":[{"url":"https:\/\/www.webhi.com\/how-to\/gilrogre\/2023\/06\/grep_regex_en.jpg"}],"author":"webhi","twitter_card":"summary_large_image","twitter_creator":"@WebHiTechnology","twitter_site":"@WebHiTechnology","twitter_misc":{"Written by":"webhi","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/#article","isPartOf":{"@id":"https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/"},"author":{"name":"webhi","@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/b31e76e2311cdc0bb90f5e2733059a54"},"headline":"Text Pattern Search in Linux with Grep &#038; Regular Expressions","datePublished":"2023-07-12T23:38:36+00:00","dateModified":"2023-07-12T23:38:45+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/"},"wordCount":1225,"commentCount":0,"publisher":{"@id":"https:\/\/www.webhi.com\/how-to\/#organization"},"articleSection":["Linux system administration"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/","url":"https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/","name":"Text Pattern Search in Linux with Grep & Regular Expressions - WebHi Tutorials &amp; Documentations","isPartOf":{"@id":"https:\/\/www.webhi.com\/how-to\/#website"},"datePublished":"2023-07-12T23:38:36+00:00","dateModified":"2023-07-12T23:38:45+00:00","description":"Discover the power of using Grep and regular expressions in Linux to efficiently search for text patterns. Learn the basics, advanced techniques, and practical examples for accurate and targeted searches in this comprehensive guide.","breadcrumb":{"@id":"https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.webhi.com\/how-to\/text-pattern-search-linux-grep-regular-expressions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webhi.com\/how-to\/"},{"@type":"ListItem","position":2,"name":"Text Pattern Search in Linux with Grep &#038; Regular Expressions"}]},{"@type":"WebSite","@id":"https:\/\/www.webhi.com\/how-to\/#website","url":"https:\/\/www.webhi.com\/how-to\/","name":"WebHi Tutorials &amp; Documentations","description":"System administration and knowledge base","publisher":{"@id":"https:\/\/www.webhi.com\/how-to\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webhi.com\/how-to\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webhi.com\/how-to\/#organization","name":"WebHi Technology","url":"https:\/\/www.webhi.com\/how-to\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/logo\/image\/","url":"https:\/\/www.webhi.com\/how-to\/gilrogre\/2022\/07\/logo.png","contentUrl":"https:\/\/www.webhi.com\/how-to\/gilrogre\/2022\/07\/logo.png","width":288,"height":95,"caption":"WebHi Technology"},"image":{"@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webhi.technology","https:\/\/twitter.com\/WebHiTechnology"]},{"@type":"Person","@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/b31e76e2311cdc0bb90f5e2733059a54","name":"webhi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/image\/","url":"https:\/\/www.webhi.com\/how-to\/ahuphiph\/litespeed\/avatar\/e20da107d0f4c765ead2eef88ad019d8.jpg?ver=1781214743","contentUrl":"https:\/\/www.webhi.com\/how-to\/ahuphiph\/litespeed\/avatar\/e20da107d0f4c765ead2eef88ad019d8.jpg?ver=1781214743","caption":"webhi"},"sameAs":["https:\/\/www.webhi.com\/how-to"],"url":"https:\/\/www.webhi.com\/how-to\/author\/webhi\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/posts\/5932"}],"collection":[{"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/comments?post=5932"}],"version-history":[{"count":6,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/posts\/5932\/revisions"}],"predecessor-version":[{"id":5959,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/posts\/5932\/revisions\/5959"}],"wp:attachment":[{"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/media?parent=5932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/categories?post=5932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/tags?post=5932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}