{"id":2374,"date":"2016-12-20T17:15:17","date_gmt":"2016-12-20T15:15:17","guid":{"rendered":"http:\/\/www.systemcodegeeks.com\/?p=2374"},"modified":"2017-12-13T15:56:13","modified_gmt":"2017-12-13T13:56:13","slug":"sed-stream-editor-example","status":"publish","type":"post","link":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/","title":{"rendered":"A Sed (Stream Editor) Example"},"content":{"rendered":"<p>This is a Sed (Stream Editor) example. A Stream Editor is used to perform basic transformations on text read from a file or a pipe. The result is sent to standard output. The syntax for the sed command has no output file specification, but results can be saved to a file using output redirection. The editor does not modify the original input.<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n[ulp id=&#8217;SG9vnnKgRCD7iZxf&#8217;]<br \/>\n&nbsp;<br \/>\nWhat distinguishes sed from other editors, such as vi and ed, is its ability to filter text that it gets from a pipeline feed. You do not need to interact with the editor while it is running; that is why sed is sometimes called a batch editor. This feature allows use of editing commands in scripts, greatly easing repetitive editing tasks. When facing replacement of text in a large number of files, sed is a great help.<\/p>\n<p>The following table shows an overview of the whole article:<\/p>\n<div class=\"toc\">\n<h3>Table Of Contents<\/h3>\n<dl>\n<dt><a href=\"#comm\">1. SED Commands<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#comm_comm\">1.1 SED editing commands<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#comm_opt\">1.2 Sed options<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#inter\">2. Interactive editing<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#inter_line\">2.1 Printing lines containing a pattern<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#inter_delete\">2.2 Deleting lines of input containing a pattern<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#inter_range\">2.3 Ranges of lines<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#inter_find\">2.4 Find and replace with sed<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#nonint\">3. Non-interactive editing<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#noint_read\">3.1 Reading sed commands from a file<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#noint_write\">3.2 Writing output files<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#summary\">4. Summary<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2><a name=\"comm\"><\/a>1. SED Commands<\/h2>\n<p>The sed program can perform text pattern substitutions and deletions using regular expressions, like the ones used with the grep command. The editing commands are similar to the ones used in the vi editor.<\/p>\n<h3><a name=\"comm_comm\"><\/a>1.1 SED editing commands<\/h3>\n<table>\n<tbody>\n<tr>\n<th>Command<\/th>\n<th>Result<\/th>\n<\/tr>\n<tr>\n<td>a\\<\/td>\n<td>Append text below current line.<\/td>\n<\/tr>\n<tr>\n<td>c\\<\/td>\n<td>Change text in the current line with new text.<\/td>\n<\/tr>\n<tr>\n<td>d<\/td>\n<td>Delete text.<\/td>\n<\/tr>\n<tr>\n<td>i\\<\/td>\n<td>Insert text above current line.<\/td>\n<\/tr>\n<tr>\n<td>p<\/td>\n<td>Print text.<\/td>\n<\/tr>\n<tr>\n<td>r<\/td>\n<td>Read a file.<\/td>\n<\/tr>\n<tr>\n<td>s<\/td>\n<td>Search and replace text.<\/td>\n<\/tr>\n<tr>\n<td>w<\/td>\n<td>Write to a file.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><a name=\"comm_opt\"><\/a>1.2 Sed options<\/h3>\n<table>\n<tbody>\n<tr>\n<th>Option<\/th>\n<th>Effect<\/th>\n<\/tr>\n<tr>\n<td>-e SCRIPT<\/td>\n<td>Add the commands in SCRIPT to the set of commands to be run while processing the input.<\/td>\n<\/tr>\n<tr>\n<td>-f<\/td>\n<td>Add the commands contained in the file SCRIPT-FILE to the set of commands to be run while processing the input.<\/td>\n<\/tr>\n<tr>\n<td>-n<\/td>\n<td>Silent mode.<\/td>\n<\/tr>\n<tr>\n<td>-V<\/td>\n<td>Print version information and exit.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><a name=\"inter\"><\/a>2. Interactive editing<\/h2>\n<h3><a name=\"inter_line\"><\/a>2.1 Printing lines containing a pattern<\/h3>\n<p>This is something you can do with grep, of course, but you can&#8217;t do a &#8220;find and replace&#8221; using that command. This is just to get you started.<\/p>\n<p>This is our example text file:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Test.txt<\/em><\/span><\/p>\n<pre class=\"brush:xml\">We shall not spend a large expense of time\r\nBefore we reckon with your several loves,\r\nAnd make us even with you. My thanes and kinsmen,\r\nHenceforth be earls, the first that ever Scotland\r\nIn such an honour named. What's more to do,\r\nWhich would be planted newly with the time,\r\nAs calling home our exiled friends abroad\r\nThat fled the snares of watchful tyranny;\r\nProducing forth the cruel ministers\r\nOf this dead butcher and his fiend-like queen,\r\nWho, as 'tis thought, by self and violent hands\r\nTook off her life; this, and what needful else\r\nThat calls upon us, by the grace of Grace,\r\nWe will perform in measure, time and place:\r\nSo, thanks to all at once and to each one,\r\nWhom we invite to see us crown'd at Scone.\r\nMacbeth, William Shakespeare\r\n<\/pre>\n<p>We want sed to find all the lines containing our search pattern, in this case &#8220;erors&#8221;. We use the p to obtain the result:<\/p>\n<figure id=\"attachment_2363\" aria-describedby=\"caption-attachment-2363\" style=\"width: 571px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample01.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2363\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample01.jpg\" alt=\"A SED Search Pattern Example.\" width=\"571\" height=\"487\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample01.jpg 571w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample01-300x256.jpg 300w\" sizes=\"(max-width: 571px) 100vw, 571px\" \/><\/a><figcaption id=\"caption-attachment-2363\" class=\"wp-caption-text\">A SED Search Pattern Example.<\/figcaption><\/figure>\n<p>As you notice, sed prints the entire file, but the lines containing the search string are printed twice. This is not what we want. In order to only print those lines matching our pattern, use the -n option:<\/p>\n<figure id=\"attachment_2364\" aria-describedby=\"caption-attachment-2364\" style=\"width: 571px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample02.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2364\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample02.jpg\" alt=\"A SED Search Pattern Example without duplicates.\" width=\"571\" height=\"327\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample02.jpg 571w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample02-300x172.jpg 300w\" sizes=\"(max-width: 571px) 100vw, 571px\" \/><\/a><figcaption id=\"caption-attachment-2364\" class=\"wp-caption-text\">A SED Search Pattern Example without duplicates.<\/figcaption><\/figure>\n<h3><a name=\"inter_delete\"><\/a>2.2 Deleting lines of input containing a pattern<\/h3>\n<p>We use the same example text file. Now we only want to see the lines not containing the search string:<\/p>\n<figure id=\"attachment_2365\" aria-describedby=\"caption-attachment-2365\" style=\"width: 571px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample03.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2365\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample03.jpg\" alt=\"A SED Search Pattern Example without lines containing &quot;you&quot;.\" width=\"571\" height=\"447\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample03.jpg 571w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample03-300x235.jpg 300w\" sizes=\"(max-width: 571px) 100vw, 571px\" \/><\/a><figcaption id=\"caption-attachment-2365\" class=\"wp-caption-text\">A SED Search Pattern Example without lines containing &#8220;you&#8221;.<\/figcaption><\/figure>\n<p>The d command results in excluding lines from being displayed. Matching lines starting with a given pattern and ending in a second pattern are showed like this:<\/p>\n<figure id=\"attachment_2366\" aria-describedby=\"caption-attachment-2366\" style=\"width: 571px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample04.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2366\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample04.jpg\" alt=\"A SED Search Pattern Example with a given pattern and ending in a second pattern.\" width=\"571\" height=\"307\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample04.jpg 571w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample04-300x160.jpg 300w\" sizes=\"(max-width: 571px) 100vw, 571px\" \/><\/a><figcaption id=\"caption-attachment-2366\" class=\"wp-caption-text\">A SED Search Pattern Example with a given pattern and ending in a second pattern.<\/figcaption><\/figure>\n<p>Note that the last dot needs to be escaped in order to actually match. In our example the expression just matches any character, including the last dot.<\/p>\n<h3><a name=\"inter_range\"><\/a>2.3 Ranges of lines<\/h3>\n<p>This time we want to take out the lines containing the errors. In the example these are lines 2 to 4. Specify this range to address, together with the d command:<\/p>\n<figure id=\"attachment_2367\" aria-describedby=\"caption-attachment-2367\" style=\"width: 571px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample05.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2367\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample05.jpg\" alt=\"A SED range of line Example.\" width=\"571\" height=\"427\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample05.jpg 571w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample05-300x224.jpg 300w\" sizes=\"(max-width: 571px) 100vw, 571px\" \/><\/a><figcaption id=\"caption-attachment-2367\" class=\"wp-caption-text\">A SED range of line Example.<\/figcaption><\/figure>\n<p>To print the file starting from a certain line until the end of the file, use a command similar to this:<\/p>\n<figure id=\"attachment_2368\" aria-describedby=\"caption-attachment-2368\" style=\"width: 571px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample06.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2368\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample06.jpg\" alt=\"Another SED range of line Example.\" width=\"571\" height=\"307\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample06.jpg 571w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample06-300x160.jpg 300w\" sizes=\"(max-width: 571px) 100vw, 571px\" \/><\/a><figcaption id=\"caption-attachment-2368\" class=\"wp-caption-text\">Another SED range of line Example.<\/figcaption><\/figure>\n<p>This only prints the first two lines of the example file. The following command prints the first line containing the pattern &#8220;a text&#8221;, up to and including the next line<br \/>\ncontaining the pattern &#8220;a line&#8221;:<\/p>\n<figure id=\"attachment_2369\" aria-describedby=\"caption-attachment-2369\" style=\"width: 571px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample07.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2369\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample07.jpg\" alt=\"A SED range of line Example with two patterns.\" width=\"571\" height=\"307\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample07.jpg 571w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample07-300x160.jpg 300w\" sizes=\"(max-width: 571px) 100vw, 571px\" \/><\/a><figcaption id=\"caption-attachment-2369\" class=\"wp-caption-text\">A SED range of line Example with two patterns.<\/figcaption><\/figure>\n<h3><a name=\"inter_find\"><\/a>2.4 Find and replace with sed<\/h3>\n<p>In the example file, we will now search and replace the errors instead of only (de)selecting the lines containing the search string.<\/p>\n<figure id=\"attachment_2370\" aria-describedby=\"caption-attachment-2370\" style=\"width: 571px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample08.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2370\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample08.jpg\" alt=\"A simple SED Find and Replace Example.\" width=\"571\" height=\"487\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample08.jpg 571w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample08-300x256.jpg 300w\" sizes=\"(max-width: 571px) 100vw, 571px\" \/><\/a><figcaption id=\"caption-attachment-2370\" class=\"wp-caption-text\">A simple SED Find and Replace Example.<\/figcaption><\/figure>\n<p>To insert a string at the beginning of each line of a file, for instance for quoting:<\/p>\n<figure id=\"attachment_2371\" aria-describedby=\"caption-attachment-2371\" style=\"width: 571px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample09.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2371\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample09.jpg\" alt=\"A SED String insertion Example.\" width=\"571\" height=\"487\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample09.jpg 571w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample09-300x256.jpg 300w\" sizes=\"(max-width: 571px) 100vw, 571px\" \/><\/a><figcaption id=\"caption-attachment-2371\" class=\"wp-caption-text\">A SED String insertion Example.<\/figcaption><\/figure>\n<p>Insert some string at the end of each line:<\/p>\n<figure id=\"attachment_2372\" aria-describedby=\"caption-attachment-2372\" style=\"width: 571px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample10.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2372\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample10.jpg\" alt=\"Another SED String insertion Example.\" width=\"571\" height=\"487\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample10.jpg 571w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample10-300x256.jpg 300w\" sizes=\"(max-width: 571px) 100vw, 571px\" \/><\/a><figcaption id=\"caption-attachment-2372\" class=\"wp-caption-text\">Another SED String insertion Example.<\/figcaption><\/figure>\n<p>Multiple find and replace commands are separated with individual -e options:<\/p>\n<figure id=\"attachment_2373\" aria-describedby=\"caption-attachment-2373\" style=\"width: 571px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample11.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2373\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample11.jpg\" alt=\"A Sed Example with multiple find and replace commands.\" width=\"571\" height=\"487\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample11.jpg 571w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/SedExample11-300x256.jpg 300w\" sizes=\"(max-width: 571px) 100vw, 571px\" \/><\/a><figcaption id=\"caption-attachment-2373\" class=\"wp-caption-text\">A Sed Example with multiple find and replace commands.<\/figcaption><\/figure>\n<p>Keep in mind that by default sed prints its results to the standard output, most likely your terminal window. If<br \/>\nyou want to save the output to a file, redirect it:<\/p>\n<pre class=\"brush:xml\">sed option 'some\/expression' file_to_process &gt; sed_output_in_a_file\r\n<\/pre>\n<h2><a name=\"nonint\"><\/a>3. Non-interactive editing<\/h2>\n<h3><a name=\"noint_read\"><\/a>3.1 Reading sed commands from a file<\/h3>\n<p>Multiple sed commands can be put in a file and executed using the -f option. When creating such a file,<br \/>\nmake sure that:<\/p>\n<ul>\n<li>No trailing white spaces exist at the end of lines.<\/li>\n<li>No quotes are used.<\/li>\n<li>When entering text to add or replace, all except the last line end in a backslash.<\/li>\n<\/ul>\n<h3><a name=\"noint_write\"><\/a>3.2 Writing output files<\/h3>\n<p>Writing output is done using the output redirection operator &gt;. This is an example script used to create very simple HTML files from plain text files.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>script.sed<\/em><\/span><\/p>\n<pre class=\"brush:xml\">1i\\\r\n&lt;html&gt;\\\r\n&lt;head&gt;&lt;title&gt;generated html by sed&lt;\/title&gt;&lt;\/head&gt;\\\r\n&lt;body bgcolor=\"#ffffff\"&gt;\\\r\n&lt;pre&gt;\r\n$a\\\r\n&lt;\/pre&gt;\\\r\n&lt;\/body&gt;\\\r\n&lt;\/html&gt;\r\n<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>txt2html.sh<\/em><\/span><\/p>\n<pre class=\"brush:xml\">#!\/bin\/bash\r\n# This is a simple script that you can use for converting text into HTML.\r\n# First we take out all newline characters, so that the appending only happens\r\n# once, then we replace the newlines.\r\necho \"converting $1...\"\r\nSCRIPT=\"script.sed\"\r\nNAME=\"$1\"\r\nRESULT=\"$2\"\r\nTEMPFILE=\"sed.$PID.tmp\"\r\nsed \"s\/\\n\/^M\/\" $NAME | sed -f $SCRIPT | sed \"s\/^M\/\\n\/\" &gt; $TEMPFILE\r\nmv $TEMPFILE $RESULT\r\necho \"done.\"\r\n<\/pre>\n<p>$1 holds the first argument to a given command, in this case the name of the file to convert:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>input.txt<\/em><\/span><\/p>\n<pre class=\"brush:xml\">This\r\nis\r\na\r\nsed\r\ngenerated\r\nhtml\r\nfile\r\n<\/pre>\n<p>After transforming we get the following output:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>output.txt<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;html&gt;\r\n&lt;head&gt;&lt;title&gt;generated html by sed&lt;\/title&gt;&lt;\/head&gt;\r\n&lt;body bgcolor=\"#ffffff\"&gt;\r\n&lt;pre&gt;\r\nThis\r\nis\r\na\r\nsed\r\ngenerated\r\nhtml\r\nfile\r\n&lt;\/pre&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>This is not really how it is done; this example just demonstrates sed capabilities.<\/p>\n<h2><a name=\"summary\"><\/a>4. Summary<\/h2>\n<p>The sed stream editor is a powerful command line tool, which can handle streams of data: it can take input lines from a pipe. This makes it fit for non-interactive use. The sed editor uses vi-like commands and accepts regular expressions.<\/p>\n<p>The sed tool can read commands from the command line or from a script. It is often used to perform find-and-replace actions on lines containing a pattern.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a Sed (Stream Editor) example. A Stream Editor is used to perform basic transformations on text read from a file or a pipe. The result is sent to standard output. The syntax for the sed command has no output file specification, but results can be saved to a file using output redirection. The &hellip;<\/p>\n","protected":false},"author":35,"featured_media":185,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[103,104],"class_list":["post-2374","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash","tag-sed","tag-stream-editor"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>A Sed (Stream Editor) Example - System Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"This is a Sed (Stream Editor) example. A Stream Editor is used to perform basic transformations on text read from a file or a pipe.\" \/>\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.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A Sed (Stream Editor) Example - System Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"This is a Sed (Stream Editor) example. A Stream Editor is used to perform basic transformations on text read from a file or a pipe.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/\" \/>\n<meta property=\"og:site_name\" content=\"System Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/systemcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2016-12-20T15:15:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-12-13T13:56:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Andreas Pomarolli\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@systemcodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@systemcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andreas Pomarolli\" \/>\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\":\"Article\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/\"},\"author\":{\"name\":\"Andreas Pomarolli\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/add1d14bc9f6218cde89909a5d3cc574\"},\"headline\":\"A Sed (Stream Editor) Example\",\"datePublished\":\"2016-12-20T15:15:17+00:00\",\"dateModified\":\"2017-12-13T13:56:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/\"},\"wordCount\":1085,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg\",\"keywords\":[\"sed\",\"stream editor\"],\"articleSection\":[\"BASH\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/\",\"url\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/\",\"name\":\"A Sed (Stream Editor) Example - System Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg\",\"datePublished\":\"2016-12-20T15:15:17+00:00\",\"dateModified\":\"2017-12-13T13:56:13+00:00\",\"description\":\"This is a Sed (Stream Editor) example. A Stream Editor is used to perform basic transformations on text read from a file or a pipe.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/#primaryimage\",\"url\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg\",\"contentUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.systemcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Shell Scripting\",\"item\":\"https:\/\/www.systemcodegeeks.com\/category\/shell-scripting\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"BASH\",\"item\":\"https:\/\/www.systemcodegeeks.com\/category\/shell-scripting\/bash\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"A Sed (Stream Editor) Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#website\",\"url\":\"https:\/\/www.systemcodegeeks.com\/\",\"name\":\"System Code Geeks\",\"description\":\"Operating System Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.systemcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.systemcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/systemcodegeeks\",\"https:\/\/x.com\/systemcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/add1d14bc9f6218cde89909a5d3cc574\",\"name\":\"Andreas Pomarolli\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e36c8f6d54df9db449aa16b2d6ddc1077d50d5e1ff3be0f0b6809081138f01fd?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e36c8f6d54df9db449aa16b2d6ddc1077d50d5e1ff3be0f0b6809081138f01fd?s=96&d=mm&r=g\",\"caption\":\"Andreas Pomarolli\"},\"description\":\"Andreas has graduated from Computer Science and Bioinformatics at the University of Linz. During his studies he has been involved with a large number of research projects ranging from software engineering to data engineering and at least web engineering. His scientific focus includes the areas of software engineering, data engineering, web engineering and project management. He currently works as a software engineer in the IT sector where she is mainly involved with projects based on Java, Databases and Web Technologies.\",\"sameAs\":[\"https:\/\/www.systemcodegeeks.com\"],\"url\":\"https:\/\/www.systemcodegeeks.com\/author\/andreas-pomarolli\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"A Sed (Stream Editor) Example - System Code Geeks - 2026","description":"This is a Sed (Stream Editor) example. A Stream Editor is used to perform basic transformations on text read from a file or a pipe.","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.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/","og_locale":"en_US","og_type":"article","og_title":"A Sed (Stream Editor) Example - System Code Geeks - 2026","og_description":"This is a Sed (Stream Editor) example. A Stream Editor is used to perform basic transformations on text read from a file or a pipe.","og_url":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/","og_site_name":"System Code Geeks","article_publisher":"https:\/\/www.facebook.com\/systemcodegeeks","article_published_time":"2016-12-20T15:15:17+00:00","article_modified_time":"2017-12-13T13:56:13+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg","type":"image\/jpeg"}],"author":"Andreas Pomarolli","twitter_card":"summary_large_image","twitter_creator":"@systemcodegeeks","twitter_site":"@systemcodegeeks","twitter_misc":{"Written by":"Andreas Pomarolli","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/#article","isPartOf":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/"},"author":{"name":"Andreas Pomarolli","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/add1d14bc9f6218cde89909a5d3cc574"},"headline":"A Sed (Stream Editor) Example","datePublished":"2016-12-20T15:15:17+00:00","dateModified":"2017-12-13T13:56:13+00:00","mainEntityOfPage":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/"},"wordCount":1085,"commentCount":0,"publisher":{"@id":"https:\/\/www.systemcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg","keywords":["sed","stream editor"],"articleSection":["BASH"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/","url":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/","name":"A Sed (Stream Editor) Example - System Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.systemcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/#primaryimage"},"image":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg","datePublished":"2016-12-20T15:15:17+00:00","dateModified":"2017-12-13T13:56:13+00:00","description":"This is a Sed (Stream Editor) example. A Stream Editor is used to perform basic transformations on text read from a file or a pipe.","breadcrumb":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/#primaryimage","url":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg","contentUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/sed-stream-editor-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.systemcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Shell Scripting","item":"https:\/\/www.systemcodegeeks.com\/category\/shell-scripting\/"},{"@type":"ListItem","position":3,"name":"BASH","item":"https:\/\/www.systemcodegeeks.com\/category\/shell-scripting\/bash\/"},{"@type":"ListItem","position":4,"name":"A Sed (Stream Editor) Example"}]},{"@type":"WebSite","@id":"https:\/\/www.systemcodegeeks.com\/#website","url":"https:\/\/www.systemcodegeeks.com\/","name":"System Code Geeks","description":"Operating System Developers Resource Center","publisher":{"@id":"https:\/\/www.systemcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.systemcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.systemcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.systemcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/systemcodegeeks","https:\/\/x.com\/systemcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/add1d14bc9f6218cde89909a5d3cc574","name":"Andreas Pomarolli","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e36c8f6d54df9db449aa16b2d6ddc1077d50d5e1ff3be0f0b6809081138f01fd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e36c8f6d54df9db449aa16b2d6ddc1077d50d5e1ff3be0f0b6809081138f01fd?s=96&d=mm&r=g","caption":"Andreas Pomarolli"},"description":"Andreas has graduated from Computer Science and Bioinformatics at the University of Linz. During his studies he has been involved with a large number of research projects ranging from software engineering to data engineering and at least web engineering. His scientific focus includes the areas of software engineering, data engineering, web engineering and project management. He currently works as a software engineer in the IT sector where she is mainly involved with projects based on Java, Databases and Web Technologies.","sameAs":["https:\/\/www.systemcodegeeks.com"],"url":"https:\/\/www.systemcodegeeks.com\/author\/andreas-pomarolli\/"}]}},"_links":{"self":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/posts\/2374","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/comments?post=2374"}],"version-history":[{"count":0,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/posts\/2374\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/media\/185"}],"wp:attachment":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/media?parent=2374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/categories?post=2374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/tags?post=2374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}