{"id":59112,"date":"2023-11-09T15:01:41","date_gmt":"2023-11-09T07:01:41","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=59112"},"modified":"2023-11-08T20:16:20","modified_gmt":"2023-11-08T12:16:20","slug":"linux-command-sed","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/linux-command-sed\/","title":{"rendered":"How to Use the sed Command in Linux"},"content":{"rendered":"<p>The name sed stands for \u201cStream Editor,\u201d and it\u2019s a powerful utility that allows you to parse and transform text right from the command line. Whether you\u2019re dealing with configuration files, scripts, or even plain text, <code>sed<\/code> is your go-to tool for quick and efficient text manipulation.<\/p>\n<p>The primary use of <code>sed<\/code> is to search for specific patterns of text and replace them with something else. It can also delete or insert lines and perform other text transformations. It\u2019s particularly useful for batch editing of files or for working within shell scripts to automate various tasks.<\/p>\n<p>While sed is incredibly versatile on its own, it\u2019s often used in combination with other Linux commands like <code>awk<\/code> for text processing, <code><a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-grep\/\">grep<\/a><\/code> for pattern searching, and <code><a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-cat\/\">cat<\/a><\/code> for displaying file content. Together, these tools form a robust toolkit for text processing in the Linux environment.<\/p>\n<p>General syntax for <code>sed<\/code> command:<\/p>\n<pre>\r\n$ sed [OPTIONS] [FILE]...\r\n<\/pre>\n<hr>\n<h3>1. Text substitution<\/h3>\n<pre>echo \"Text\" | sed 's\/Replaceable_Word\/The_Word_That_Replaces\/'<\/pre>\n<p>Use the <code>sed<\/code> command to search and replace any part of the text. <code>'s'<\/code> indicates a search and replace task.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>Let\u2019s say you have a string \u201c<code>I love CSS<\/code>\u201d and you want to replace \u201cCSS\u201d with \u201c<code>CSS Libraries<\/code>\u201c.<\/p>\n<pre>echo \"I love CSS\" | sed 's\/CSS\/CSS Libraries\/'<\/pre>\n<pre>I love CSS Libraries<\/pre>\n<p>In this example, the echo command outputs \u201c<code>I love CSS<\/code>\u201c, and then sed replaces \u201c<code>CSS<\/code>\u201d with \u201c<code>CSS Libraries<\/code>\u201c. The final output is \u201c<code>I love CSS Libraries<\/code>\u201c.<\/p>\n<hr>\n<h3>2. Replace text on a specific line in a file<\/h3>\n<pre>sed '[line] s\/harder\/easier\/g' [file]<\/pre>\n<p>The <code>'g'<\/code> option of the <code>sed<\/code> command is used to replace anything that matches the pattern.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>Let\u2019s say you have a text file named <code>example.txt<\/code> with the following content:<\/p>\n<pre>Life is hard.\r\nWorking harder is the key to success.\r\nThe harder you work, the luckier you get.<\/pre>\n<p>To replace all occurrences of the word \u201c<code>harder<\/code>\u201d with \u201c<code>easier<\/code>\u201d on line 2 of <code>example.txt<\/code>, you would run:<\/p>\n<pre>sed '2 s\/harder\/easier\/g' example.txt<\/pre>\n<p>After running the command, the output displayed on the terminal would be:<\/p>\n<pre>Life is hard.\r\nWorking easier is the key to success.\r\nThe harder you work, the luckier you get.<\/pre>\n<p>Note that the word \u201c<code>harder<\/code>\u201d is replaced with \u201c<code>easier<\/code>\u201d only on line 2.<\/p>\n<p>If you want to save these changes back to the file, you can use the <code>-i<\/code> option:<\/p>\n<pre>sed -i '2 s\/harder\/easier\/g' example.txt<\/pre>\n<p>After running this command, the content of <code>example.txt<\/code> will be permanently changed to:<\/p>\n<pre>Life is hard.\r\nWorking easier is the key to success.\r\nThe harder you work, the luckier you get.<\/pre>\n<hr>\n<h3>3. Replace first matching with new text<\/h3>\n<pre>sed 's\/harder\/easier\/' [file]<\/pre>\n<p>This command replaces only the first match of the search pattern.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>Let\u2019s say you have a text file named <code>example.txt<\/code> with the following content:<\/p>\n<pre>Life is harder than we think.\r\nWorking harder is the key to success.\r\nNo pain, no gain. Work harder.<\/pre>\n<p>You can use the sed command to replace the word \u201c<code>harder<\/code>\u201d with \u201c<code>easier<\/code>\u201d in each line:<\/p>\n<pre>sed 's\/harder\/easier\/' example.txt<\/pre>\n<p>After running the command, the output will be:<\/p>\n<pre>Life is easier than we think.\r\nWorking easier is the key to success.\r\nNo pain, no gain. Work easier.<\/pre>\n<hr>\n<h3>4. Remove matching lines<\/h3>\n<pre>sed '\/Something\/d' example.txt<\/pre>\n<p>Use the <code>d<\/code> option of the <code>sed<\/code> command to remove any line from a file.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>Let\u2019s say you have a file called <code>example.txt<\/code> with the following content:<\/p>\n<pre>\r\nHello World\r\nSomething is here\r\nAnother line\r\nYet another line\r\nSomething else<\/pre>\n<p>Running the command <code>sed '\/Something\/d' example.txt<\/code> will output:<\/p>\n<pre>\r\nHello World\r\nAnother line\r\nYet another line<\/pre>\n<hr>\n<h3>5. Search for a case-insensitive word + delete it<\/h3>\n<pre>sed '\/Sample\/Id' example.txt<\/pre>\n<p>The <code>I<\/code> option of the <code>sed<\/code> command is used to search for a matching pattern in a case insensitive way.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>Let\u2019s say you have a file named <code>example.txt<\/code> with the following content:<\/p>\n<pre>This is a Sample line.\r\nAnother line.\r\nYet another Sample line.\r\nFinal line.<\/pre>\n<p>Running the <code>command sed '\/Sample\/Id' example.txt<\/code> will produce the following output:<\/p>\n<pre>Another line.\r\nFinal line.<\/pre>\n<hr>\n<h3>6. Replace words with uppercase<\/h3>\n<pre>sed 's\/\\(libraries\\)\/\\U\\1\/Ig' example.txt<\/pre>\n<p>Use the <code>U<\/code> option of the <code>sed<\/code> command to convert any text to uppercase letters.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>Let\u2019s say you have a file named <code>example.txt<\/code> with the following content:<\/p>\n<pre>I love libraries.\r\nlibraries are great.\r\nYou can find many books in libraries.<\/pre>\n<p>After running the <code>sed<\/code> command, the output will be:<\/p>\n<pre>I love LIBRARIES.\r\nLIBRARIES are great.\r\nYou can find many books in LIBRARIES.<\/pre>\n<hr>\n<h3>7. Replace words with lowercase<\/h3>\n<pre>sed 's\/\\(libraries\\)\/\\L\\1\/Ig' example.txt<\/pre>\n<p>The <code>L<\/code> option of the <code>sed<\/code> command is used to convert any text to lowercase letters.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>Let\u2019s say you have a file named <code>example.txt<\/code> with the following content:<\/p>\n<pre>Libraries are essential for research.\r\nlibraries help in many ways.\r\nI love LIBRARIES!<\/pre>\n<p>After running the <code>sed<\/code> command, the output will be:<\/p>\n<pre>libraries are essential for research.\r\nlibraries help in many ways.\r\nI love libraries!<\/pre>\n<hr>\n<h3>8. Insert blank lines in a file<\/h3>\n<pre>sed G [file]<\/pre>\n<p>Use the <code>G<\/code> option of the <code>sed<\/code> command to insert blank lines after each line of the file.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>Let\u2019s say you have a file called <code>example.txt<\/code> with the following content:<\/p>\n<pre>Hello\r\nWorld\r\nThis\r\nIs\r\nA\r\nTest<\/pre>\n<p>You can run the following command to append an extra newline at the end of each line:<\/p>\n<pre>sed G example.txt<\/pre>\n<p>After running the command, the output will be:<\/p>\n<pre>Hello\r\n\r\nWorld\r\n\r\nThis\r\n\r\nIs\r\n\r\nA\r\n\r\nTest<\/pre>\n<hr>\n<h3>9. Print file\u2019s line numbers<\/h3>\n<pre>sed '=' [file]<\/pre>\n<p>The <code>=<\/code> sign is used to print a line number before each line of text in a file.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>Let\u2019s say you have a file named <code>example.txt<\/code> with the following content:<\/p>\n<pre>Hello\r\nWorld\r\nThis\r\nIs\r\nA\r\nTest<\/pre>\n<p>You can run the following command to print the line numbers before each line:<\/p>\n<pre>sed '=' example.txt<\/pre>\n<pre>1\r\nHello\r\n2\r\nWorld\r\n3\r\nThis\r\n4\r\nIs\r\n5\r\nA\r\n6\r\nTest\r\n<\/pre>\n<hr>\n<h3 style=\"padding-bottom:10px\">More Linux commands:<\/h3>\n<table>\n<tbody>\n<tr>\n<td width=\"150\">Directory Operations<\/td>\n<td><a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-rm-rmdir\/\"><code>rmdir<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-cd\/\"><code>cd<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-pwd\/\"><code>pwd<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-exa\/\"><code>exa<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-ls\/\"><code>ls<\/code><\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"150\">File Operations<\/td>\n<td><a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-cat\/\"><code>cat<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-cp\/\"><code>cp<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-dd\/\"><code>dd<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-less\/\"><code>less<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-touch\/\"><code>touch<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-ln\/\"><code>ln<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-rename\/\"><code>rename<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-more\/\"><code>more<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-head\/\"><code>head<\/code><\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"150\">File System Operations<\/td>\n<td><a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-chown\/\"><code>chown<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-mkfs\/\"><code>mkfs<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-locate\/\"><code>locate<\/code><\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"150\">Networking<\/td>\n<td><a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-ping\/\"><code>ping<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-curl\/\"><code>curl<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-wget\/\"><code>wget<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-iptables\/\"><code>iptables<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-mtr\/\"><code>mtr<\/code><\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"150\">Search and Text Processing<\/td>\n<td><a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-find\/\"><code>find<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-grep\/\"><code>grep<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-sed\/\"><code>sed<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-whatis\/\"><code>whatis<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-ripgrep\/\"><code>ripgrep<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-fd\/\"><code>fd<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-tldr\/\"><code>tldr<\/code><\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"150\">System Information and Management<\/td>\n<td><a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-env\/\"><code>env<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-history\/\"><code>history<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-top\/\"><code>top<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-who\/\"><code>who<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-htop\/\"><code>htop<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-glances\/\"><code>glances<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-lsof\/\"><code>lsof<\/code><\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"150\">User and Session Management<\/td>\n<td><a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-screen\/\"><code>screen<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-su\/\"><code>su<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-sudo\/\"><code>sudo<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-open\/\"><code>open<\/code><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>","protected":false},"excerpt":{"rendered":"<p>The name sed stands for \u201cStream Editor,\u201d and it\u2019s a powerful utility that allows you to parse and transform text right from the command line. Whether you\u2019re dealing with configuration files, scripts, or even plain text, sed is your go-to tool for quick and efficient text manipulation. The primary use of sed is to search&hellip;<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3397],"tags":[888,3316],"topic":[],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.6) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Use the sed Command in Linux - Hongkiat<\/title>\n<meta name=\"description\" content=\"The name sed stands for &quot;Stream Editor,&quot; and it&#039;s a powerful utility that allows you to parse and transform text right from the command line. Whether\" \/>\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.hongkiat.com\/blog\/linux-command-sed\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Use the sed Command in Linux\" \/>\n<meta property=\"og:description\" content=\"The name sed stands for &quot;Stream Editor,&quot; and it&#039;s a powerful utility that allows you to parse and transform text right from the command line. Whether\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/linux-command-sed\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-09T07:01:41+00:00\" \/>\n<meta name=\"author\" content=\"Hongkiat.com\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Hongkiat.com\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/linux-command-sed\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/linux-command-sed\\\/\"},\"author\":{\"name\":\"Hongkiat.com\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/7cc686597d92f9086729e4bcc1577ba3\"},\"headline\":\"How to Use the sed Command in Linux\",\"datePublished\":\"2023-11-09T07:01:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/linux-command-sed\\\/\"},\"wordCount\":627,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"keywords\":[\"Linux\",\"Linux Commands\"],\"articleSection\":[\"Desktop\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/linux-command-sed\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/linux-command-sed\\\/\",\"name\":\"How to Use the sed Command in Linux - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"datePublished\":\"2023-11-09T07:01:41+00:00\",\"description\":\"The name sed stands for \\\"Stream Editor,\\\" and it's a powerful utility that allows you to parse and transform text right from the command line. Whether\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/linux-command-sed\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/linux-command-sed\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/linux-command-sed\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Use the sed Command in Linux\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/7cc686597d92f9086729e4bcc1577ba3\",\"name\":\"Hongkiat.com\",\"description\":\"This post is published by an HKDC (hongkiat.com) staff. (I.e., intern, staff writer, or editor).\",\"sameAs\":[\"https:\\\/\\\/www.hongkiat.com\"],\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Use the sed Command in Linux - Hongkiat","description":"The name sed stands for \"Stream Editor,\" and it's a powerful utility that allows you to parse and transform text right from the command line. Whether","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.hongkiat.com\/blog\/linux-command-sed\/","og_locale":"en_US","og_type":"article","og_title":"How to Use the sed Command in Linux","og_description":"The name sed stands for \"Stream Editor,\" and it's a powerful utility that allows you to parse and transform text right from the command line. Whether","og_url":"https:\/\/www.hongkiat.com\/blog\/linux-command-sed\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2023-11-09T07:01:41+00:00","author":"Hongkiat.com","twitter_card":"summary_large_image","twitter_creator":"@hongkiat","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Hongkiat.com","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/linux-command-sed\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/linux-command-sed\/"},"author":{"name":"Hongkiat.com","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/7cc686597d92f9086729e4bcc1577ba3"},"headline":"How to Use the sed Command in Linux","datePublished":"2023-11-09T07:01:41+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/linux-command-sed\/"},"wordCount":627,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"keywords":["Linux","Linux Commands"],"articleSection":["Desktop"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/linux-command-sed\/","url":"https:\/\/www.hongkiat.com\/blog\/linux-command-sed\/","name":"How to Use the sed Command in Linux - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"datePublished":"2023-11-09T07:01:41+00:00","description":"The name sed stands for \"Stream Editor,\" and it's a powerful utility that allows you to parse and transform text right from the command line. Whether","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/linux-command-sed\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/linux-command-sed\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/linux-command-sed\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Use the sed Command in Linux"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/7cc686597d92f9086729e4bcc1577ba3","name":"Hongkiat.com","description":"This post is published by an HKDC (hongkiat.com) staff. (I.e., intern, staff writer, or editor).","sameAs":["https:\/\/www.hongkiat.com"],"url":"https:\/\/www.hongkiat.com\/blog\/author\/com\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-fnq","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/59112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=59112"}],"version-history":[{"count":4,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/59112\/revisions"}],"predecessor-version":[{"id":68918,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/59112\/revisions\/68918"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=59112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=59112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=59112"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=59112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}