{"id":3467,"date":"2024-06-25T10:00:03","date_gmt":"2024-06-25T10:00:03","guid":{"rendered":"https:\/\/draculaservers.com\/tutorials\/?p=3467"},"modified":"2024-08-04T20:25:50","modified_gmt":"2024-08-04T20:25:50","slug":"stream-editor-sed-on-linux-the-basics","status":"publish","type":"post","link":"https:\/\/draculaservers.com\/tutorials\/stream-editor-sed-on-linux-the-basics\/","title":{"rendered":"Stream Editor (SED) on Linux: The Basics"},"content":{"rendered":"<div class=\"cl-preview-section\"><\/div>\n<div class=\"cl-preview-section\">\n<p>The\u00a0<code>sed<\/code>\u00a0command, short for Stream Editor, is a powerful and versatile tool in Unix-like systems used for parsing and transforming text from a stream or a file. Unlike traditional text editors that operate interactively,\u00a0<code>sed<\/code>\u00a0works non-interactively, applying a set of editing commands to the text in a single pass. This article will guide you through the basics of\u00a0<code>sed<\/code>, including its fundamental concepts, common commands, practical examples, and best practices.<\/p>\n\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"what-is-sed\">What is\u00a0<code>sed<\/code>?<\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<p><code>sed<\/code>\u00a0stands for Stream Editor. It reads input line by line (streaming), processes it according to commands specified in its script, and then outputs the result. This makes\u00a0<code>sed<\/code>\u00a0ideal for tasks like automated text processing, bulk editing, and data extraction.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"why-use-sed\">Why Use\u00a0<code>sed<\/code>?<\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p><code>sed<\/code>\u00a0is valuable because:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<ul>\n<li><strong>Efficiency<\/strong>: It processes text quickly and efficiently, even with large files.<\/li>\n<li><strong>Automation<\/strong>: Ideal for scripts and batch processing tasks.<\/li>\n<li><strong>Powerful Editing<\/strong>: Supports complex text manipulation with a simple syntax.<\/li>\n<\/ul>\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"basic-syntax\">Basic Syntax<\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The basic syntax of the\u00a0<code>sed<\/code>\u00a0command is:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sed<\/span> <span class=\"token punctuation\">[<\/span>options<span class=\"token punctuation\">]<\/span> <span class=\"token string\">'command'<\/span> <span class=\"token function\">file<\/span>\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<ul>\n<li><strong><code>[options]<\/code><\/strong>: Optional flags to modify behavior.<\/li>\n<li><strong><code>'command'<\/code><\/strong>: The\u00a0<code>sed<\/code>\u00a0command or script to execute.<\/li>\n<li><strong><code>file<\/code><\/strong>: The input file to process.<\/li>\n<\/ul>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"example-of-basic-usage\">Example of Basic Usage<\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>To replace the first occurrence of \u201cold\u201d with \u201cnew\u201d in a file named\u00a0<code>example.txt<\/code>:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sed<\/span> <span class=\"token string\">'s\/old\/new\/'<\/span> example.txt\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"core-concepts\">Core Concepts<\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"addresses\"><span id=\"1-addresses\">1. Addresses<\/span><\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>In\u00a0<code>sed<\/code>, addresses specify which lines a command should operate on. Addresses can be:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<ul>\n<li><strong>Line Numbers<\/strong>: e.g.,\u00a0<code>2<\/code>\u00a0refers to the second line.<\/li>\n<li><strong>Patterns<\/strong>: e.g.,\u00a0<code>\/pattern\/<\/code>\u00a0refers to lines containing the specified pattern.<\/li>\n<\/ul>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Commands can be applied to specific lines or patterns. For example:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sed<\/span> <span class=\"token string\">'2s\/old\/new\/'<\/span> example.txt\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>This command replaces \u201cold\u201d with \u201cnew\u201d only on the second line.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"commands\"><span id=\"2-commands\">2. Commands<\/span><\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p><code>sed<\/code>\u00a0commands are instructions that modify text. Common commands include:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<ul>\n<li><strong><code>s<\/code>\u00a0(substitute)<\/strong>: Replaces text.<\/li>\n<li><strong><code>d<\/code>\u00a0(delete)<\/strong>: Removes lines.<\/li>\n<li><strong><code>p<\/code>\u00a0(print)<\/strong>: Outputs lines.<\/li>\n<\/ul>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Commands are usually written in single quotes, and multiple commands can be combined in a script.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"basic-commands\">Basic Commands<\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"substitution-s\"><span id=\"1-substitution-s\">1. Substitution (<code>s<\/code>)<\/span><\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The\u00a0<code>s<\/code>\u00a0command is used for substitution. Its syntax is:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sed<\/span> <span class=\"token string\">'s\/pattern\/replacement\/flags'<\/span> <span class=\"token function\">file<\/span>\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<ul>\n<li><strong><code>pattern<\/code><\/strong>: The text to search for.<\/li>\n<li><strong><code>replacement<\/code><\/strong>: The text to replace it with.<\/li>\n<li><strong><code>flags<\/code><\/strong>: Optional flags to modify the behavior.<\/li>\n<\/ul>\n<\/div>\n<div class=\"cl-preview-section\">\n<h4 id=\"example\">Example<\/h4>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>To replace all occurrences of \u201cfoo\u201d with \u201cbar\u201d:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sed<\/span> <span class=\"token string\">'s\/foo\/bar\/g'<\/span> example.txt\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The\u00a0<code>g<\/code>\u00a0flag makes the substitution global, affecting all matches on a line.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"deleting-lines-d\"><span id=\"2-deleting-lines-d\">2. Deleting Lines (<code>d<\/code>)<\/span><\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The\u00a0<code>d<\/code>\u00a0command deletes lines from the output. For example:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sed<\/span> <span class=\"token string\">'3d'<\/span> example.txt\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>This command deletes the third line from the output.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h4 id=\"pattern-based-deletion\">Pattern-Based Deletion<\/h4>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>To delete lines containing a specific pattern:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sed<\/span> <span class=\"token string\">'\/pattern\/d'<\/span> example.txt\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"printing-lines-p\"><span id=\"3-printing-lines-p\">3. Printing Lines (<code>p<\/code>)<\/span><\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The\u00a0<code>p<\/code>\u00a0command prints lines that match a pattern. For example:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sed<\/span> -n <span class=\"token string\">'\/pattern\/p'<\/span> example.txt\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The\u00a0<code>-n<\/code>\u00a0option suppresses automatic printing of pattern space, so only lines matching the pattern are printed.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"inserting-and-appending-text\"><span id=\"4-inserting-and-appending-text\">4. Inserting and Appending Text<\/span><\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<ul>\n<li><strong>Insert (<code>i<\/code>)<\/strong>: Adds text before a line.\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sed<\/span> <span class=\"token string\">'2i\\New line of text'<\/span> example.txt\r\n<\/code><\/pre>\n<\/li>\n<li><strong>Append (<code>a<\/code>)<\/strong>: Adds text after a line.\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sed<\/span> <span class=\"token string\">'2a\\New line of text'<\/span> example.txt\r\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/div>\n<div class=\"cl-preview-section\">\n<div class=\"cl-preview-section\">\n<h2 id=\"affordable-vps-hosting-with-dracula-servers\"><span style=\"color: #ff2600;\">Affordable VPS Hosting With Dracula Servers<\/span><\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Looking for reliable and budget-friendly Virtual Private Server (VPS) hosting? Look no further than\u00a0<a href=\"https:\/\/draculaservers.com\/\">Dracula Servers<\/a>. Dracula Servers offers a range of VPS hosting plans tailored to meet diverse needs. With competitive pricing, robust performance, and a user-friendly interface, it\u2019s an excellent choice for individuals and businesses alike.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Explore the\u00a0<a href=\"https:\/\/draculaservers.com\/\">Dracula Servers website<\/a> to discover hosting solutions that align with your requirements and take your online presence to new heights with their affordable and efficient VPS hosting services.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<p><a href=\"https:\/\/draculaservers.com\/\"><strong>Visit Dracula Servers<\/strong><\/a>\u00a0and experience reliable VPS hosting without breaking the bank.<\/p>\n<\/div>\n<h2 id=\"using-sed-with-regular-expressions\">Using\u00a0<code>sed<\/code>\u00a0with Regular Expressions<\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<p><code>sed<\/code>\u00a0supports regular expressions (regex) for complex pattern matching. Regular expressions enhance\u00a0<code>sed<\/code>&#8216;s power by allowing for sophisticated text searches.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"basic-regular-expressions\">Basic Regular Expressions<\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<ul>\n<li><strong><code>.<\/code><\/strong>: Matches any single character.<\/li>\n<li><strong><code>*<\/code><\/strong>: Matches zero or more occurrences of the preceding character.<\/li>\n<li><strong><code>^<\/code><\/strong>: Matches the beginning of a line.<\/li>\n<li><strong><code>$<\/code><\/strong>: Matches the end of a line.<\/li>\n<\/ul>\n<\/div>\n<div class=\"cl-preview-section\">\n<h4 id=\"example-1\"><span id=\"example-2\">Example<\/span><\/h4>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>To match lines that start with \u201cstart\u201d:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sed<\/span> <span class=\"token string\">'\/^start\/'<\/span> example.txt\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"extended-regular-expressions\">Extended Regular Expressions<\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>To use extended regex features, use the\u00a0<code>-E<\/code>\u00a0option:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sed<\/span> -E <span class=\"token string\">'\/^start[0-9]+\/'<\/span> example.txt\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>This command matches lines starting with \u201cstart\u201d followed by one or more digits.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"multi-line-editing\">Multi-Line Editing<\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<p><code>sed<\/code>\u00a0typically operates on a line-by-line basis, but you can perform multi-line edits using special patterns and commands.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"pattern-space-and-hold-space\">Pattern Space and Hold Space<\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<ul>\n<li><strong>Pattern Space<\/strong>: The current line being processed.<\/li>\n<li><strong>Hold Space<\/strong>: A secondary buffer used for temporary storage.<\/li>\n<\/ul>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"example-swapping-lines\">Example: Swapping Lines<\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>To swap the first and second lines:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sed<\/span> -e <span class=\"token string\">'1h'<\/span> -e <span class=\"token string\">'2H'<\/span> -e <span class=\"token string\">'2x'<\/span> -e <span class=\"token string\">'2d'<\/span> -e <span class=\"token string\">'1p'<\/span> example.txt\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>This command uses the hold space to store and swap lines.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"practical-examples\">Practical Examples<\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"changing-file-extensions\"><span id=\"1-changing-file-extensions\">1. Changing File Extensions<\/span><\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>To change file extensions from\u00a0<code>.txt<\/code>\u00a0to\u00a0<code>.md<\/code>:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sed<\/span> <span class=\"token string\">'s\/\\.txt\/\\.md\/'<\/span> filenames.txt\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>This replaces all occurrences of\u00a0<code>.txt<\/code>\u00a0with\u00a0<code>.md<\/code>\u00a0in the file\u00a0<code>filenames.txt<\/code>.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"removing-blank-lines\"><span id=\"2-removing-blank-lines\">2. Removing Blank Lines<\/span><\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>To remove all blank lines from a file:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sed<\/span> <span class=\"token string\">'\/^$\/d'<\/span> example.txt\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>This deletes lines that are empty.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"replacing-multiple-patterns\"><span id=\"3-replacing-multiple-patterns\">3. Replacing Multiple Patterns<\/span><\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>To replace both \u201cfoo\u201d with \u201cbar\u201d and \u201cbaz\u201d with \u201cqux\u201d:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sed<\/span> -e <span class=\"token string\">'s\/foo\/bar\/g'<\/span> -e <span class=\"token string\">'s\/baz\/qux\/g'<\/span> example.txt\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"advanced-usage\">Advanced Usage<\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"using-sed-in-scripts\">Using\u00a0<code>sed<\/code>\u00a0in Scripts<\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p><code>sed<\/code>\u00a0commands can be included in scripts for automation. Create a script file with\u00a0<code>sed<\/code>\u00a0commands and execute it to process multiple files.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h4 id=\"example-script\">Example Script<\/h4>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Create a file named\u00a0<code>replace.sh<\/code>\u00a0with the following content:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token shebang important\">#!\/bin\/bash<\/span>\r\n<span class=\"token function\">sed<\/span> -i <span class=\"token string\">'s\/foo\/bar\/g'<\/span> <span class=\"token string\">\"<span class=\"token variable\">$1<\/span>\"<\/span>\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Run the script with a file as an argument:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">bash<\/span> replace.sh example.txt\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The\u00a0<code>-i<\/code>\u00a0option edits the file in place.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"combining-sed-with-other-commands\">Combining\u00a0<code>sed<\/code>\u00a0with Other Commands<\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p><code>sed<\/code>\u00a0can be combined with other commands using pipes. For example, to count lines containing \u201cpattern\u201d:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">grep<\/span> <span class=\"token string\">'pattern'<\/span> example.txt <span class=\"token operator\">|<\/span> <span class=\"token function\">sed<\/span> -n <span class=\"token string\">'$='<\/span>\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>This counts the number of lines matching \u201cpattern\u201d.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"performance-considerations\">Performance Considerations<\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>When working with large files,\u00a0<code>sed<\/code>&#8216;s efficiency is advantageous. However, be mindful of the following:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<ul>\n<li><strong>Memory Usage<\/strong>:\u00a0<code>sed<\/code>\u00a0processes files line by line, reducing memory usage.<\/li>\n<li><strong>Execution Time<\/strong>: Complex\u00a0<code>sed<\/code>\u00a0commands can be slow; optimize commands for large datasets.<\/li>\n<\/ul>\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"security-considerations\">Security Considerations<\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>When using\u00a0<code>sed<\/code>\u00a0in scripts or command lines, be aware of:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<ul>\n<li><strong>Unintended Modifications<\/strong>: Verify commands to prevent accidental data loss.<\/li>\n<li><strong>Injection Risks<\/strong>: Avoid using unsanitized user input in\u00a0<code>sed<\/code>\u00a0commands.<\/li>\n<\/ul>\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The\u00a0<code>sed<\/code>\u00a0command is a powerful tool for text processing and manipulation in Unix-like systems. Its ability to efficiently handle text streams, combined with its support for regular expressions, makes it invaluable for a wide range of tasks, from simple substitutions to complex multi-line edits. By mastering\u00a0<code>sed<\/code>\u00a0commands and understanding its core concepts, you can effectively automate text processing, streamline workflows, and gain deeper insights into your text data. Whether you\u2019re a system administrator, developer, or power user,\u00a0<code>sed<\/code>\u00a0is an essential skill in the toolkit of anyone working with text on Linux.<\/p>\n<p>Check out More Linux Tutorials <a href=\"https:\/\/draculaservers.com\/tutorials\/\" target=\"_blank\" rel=\"noopener\">Here!<\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The\u00a0sed\u00a0command, short for Stream Editor, is a powerful and versatile tool in Unix-like systems used for parsing and transforming text from a stream or a file. Unlike traditional text editors that operate interactively,\u00a0sed\u00a0works non-interactively, applying a set of editing commands to the text in a single pass. This article will guide you through the basics [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":3469,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[172],"tags":[590,592,591],"class_list":["post-3467","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-tutorials","tag-how-to-use-the-sed-command","tag-how-to-use-the-stream-editor-on-linux","tag-sed-tool-in-linux"],"blocksy_meta":[],"featured_image_urls_v2":{"full":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-42.png",1280,720,false],"thumbnail":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-42-150x150.png",150,150,true],"medium":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-42-300x169.png",300,169,true],"medium_large":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-42-768x432.png",768,432,true],"large":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-42-1024x576.png",1024,576,true],"1536x1536":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-42.png",1280,720,false],"2048x2048":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-42.png",1280,720,false],"pk-small":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-42-80x80.png",80,80,true],"pk-thumbnail":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-42-300x225.png",300,225,true]},"post_excerpt_stackable_v2":"<p>The\u00a0sed\u00a0command, short for Stream Editor, is a powerful and versatile tool in Unix-like systems used for parsing and transforming text from a stream or a file. Unlike traditional text editors that operate interactively,\u00a0sed\u00a0works non-interactively, applying a set of editing commands to the text in a single pass. This article will guide you through the basics of\u00a0sed, including its fundamental concepts, common commands, practical examples, and best practices. What is\u00a0sed? sed\u00a0stands for Stream Editor. It reads input line by line (streaming), processes it according to commands specified in its script, and then outputs the result. This makes\u00a0sed\u00a0ideal for tasks like automated&hellip;<\/p>\n","category_list_v2":"<a href=\"https:\/\/draculaservers.com\/tutorials\/category\/linux-tutorials\/\" rel=\"category tag\">Linux Tutorials<\/a>","author_info_v2":{"name":"Abdul Mannan","url":"https:\/\/draculaservers.com\/tutorials\/author\/abdul-mannan-tbgmail-com\/"},"comments_num_v2":"0 comments","yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Stream Editor (SED) on Linux: The Basics - Dracula Servers Tutorials<\/title>\n<meta name=\"description\" content=\"The\u00a0sed\u00a0command is a powerful and versatile tool in Unix-like systems used for parsing and transforming text from a stream or a file.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/draculaservers.com\/tutorials\/stream-editor-sed-on-linux-the-basics\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Stream Editor (SED) on Linux: The Basics - Dracula Servers Tutorials\" \/>\n<meta property=\"og:description\" content=\"The\u00a0sed\u00a0command is a powerful and versatile tool in Unix-like systems used for parsing and transforming text from a stream or a file.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/draculaservers.com\/tutorials\/stream-editor-sed-on-linux-the-basics\/\" \/>\n<meta property=\"og:site_name\" content=\"Dracula Servers Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2024-06-25T10:00:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-04T20:25:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-42.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Abdul Mannan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Abdul Mannan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/stream-editor-sed-on-linux-the-basics\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/stream-editor-sed-on-linux-the-basics\\\/\"},\"author\":{\"name\":\"Abdul Mannan\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/ac89d0281f4fb596bfaa0bc1e746c8a6\"},\"headline\":\"Stream Editor (SED) on Linux: The Basics\",\"datePublished\":\"2024-06-25T10:00:03+00:00\",\"dateModified\":\"2024-08-04T20:25:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/stream-editor-sed-on-linux-the-basics\\\/\"},\"wordCount\":955,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/stream-editor-sed-on-linux-the-basics\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2024\\\/08\\\/Dracula-Servers-Thumbnail-42.png\",\"keywords\":[\"how to use the sed command\",\"How to use the stream editor on linux\",\"Sed tool in Linux\"],\"articleSection\":[\"Linux Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/stream-editor-sed-on-linux-the-basics\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/stream-editor-sed-on-linux-the-basics\\\/\",\"url\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/stream-editor-sed-on-linux-the-basics\\\/\",\"name\":\"Stream Editor (SED) on Linux: The Basics - Dracula Servers Tutorials\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/stream-editor-sed-on-linux-the-basics\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/stream-editor-sed-on-linux-the-basics\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2024\\\/08\\\/Dracula-Servers-Thumbnail-42.png\",\"datePublished\":\"2024-06-25T10:00:03+00:00\",\"dateModified\":\"2024-08-04T20:25:50+00:00\",\"description\":\"The\u00a0sed\u00a0command is a powerful and versatile tool in Unix-like systems used for parsing and transforming text from a stream or a file.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/stream-editor-sed-on-linux-the-basics\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/stream-editor-sed-on-linux-the-basics\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/stream-editor-sed-on-linux-the-basics\\\/#primaryimage\",\"url\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2024\\\/08\\\/Dracula-Servers-Thumbnail-42.png\",\"contentUrl\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2024\\\/08\\\/Dracula-Servers-Thumbnail-42.png\",\"width\":1280,\"height\":720,\"caption\":\"Stream Editor (SED): The Basics\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/stream-editor-sed-on-linux-the-basics\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Stream Editor (SED) on Linux: The Basics\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#website\",\"url\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/\",\"name\":\"Dracula Servers Tutorials\",\"description\":\"Dedicated Servers\",\"publisher\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#organization\",\"name\":\"Dracula Servers\",\"url\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2016\\\/06\\\/dracula_full_logo_smaller.png\",\"contentUrl\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2016\\\/06\\\/dracula_full_logo_smaller.png\",\"width\":1625,\"height\":200,\"caption\":\"Dracula Servers\"},\"image\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/ac89d0281f4fb596bfaa0bc1e746c8a6\",\"name\":\"Abdul Mannan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2809442d44177cab4f90e1d9b3295560462063881ca1374b6d597d8f0b48fc21?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2809442d44177cab4f90e1d9b3295560462063881ca1374b6d597d8f0b48fc21?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2809442d44177cab4f90e1d9b3295560462063881ca1374b6d597d8f0b48fc21?s=96&d=mm&r=g\",\"caption\":\"Abdul Mannan\"},\"description\":\"An individual trying to decipher the enigmas of technology by the sheer driving force of curiosity. Interested in learning new skills and being better at those skills than the lot.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Stream Editor (SED) on Linux: The Basics - Dracula Servers Tutorials","description":"The\u00a0sed\u00a0command is a powerful and versatile tool in Unix-like systems used for parsing and transforming text from a stream or a file.","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:\/\/draculaservers.com\/tutorials\/stream-editor-sed-on-linux-the-basics\/","og_locale":"en_US","og_type":"article","og_title":"Stream Editor (SED) on Linux: The Basics - Dracula Servers Tutorials","og_description":"The\u00a0sed\u00a0command is a powerful and versatile tool in Unix-like systems used for parsing and transforming text from a stream or a file.","og_url":"https:\/\/draculaservers.com\/tutorials\/stream-editor-sed-on-linux-the-basics\/","og_site_name":"Dracula Servers Tutorials","article_published_time":"2024-06-25T10:00:03+00:00","article_modified_time":"2024-08-04T20:25:50+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-42.png","type":"image\/png"}],"author":"Abdul Mannan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Abdul Mannan","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/draculaservers.com\/tutorials\/stream-editor-sed-on-linux-the-basics\/#article","isPartOf":{"@id":"https:\/\/draculaservers.com\/tutorials\/stream-editor-sed-on-linux-the-basics\/"},"author":{"name":"Abdul Mannan","@id":"https:\/\/draculaservers.com\/tutorials\/#\/schema\/person\/ac89d0281f4fb596bfaa0bc1e746c8a6"},"headline":"Stream Editor (SED) on Linux: The Basics","datePublished":"2024-06-25T10:00:03+00:00","dateModified":"2024-08-04T20:25:50+00:00","mainEntityOfPage":{"@id":"https:\/\/draculaservers.com\/tutorials\/stream-editor-sed-on-linux-the-basics\/"},"wordCount":955,"commentCount":0,"publisher":{"@id":"https:\/\/draculaservers.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/draculaservers.com\/tutorials\/stream-editor-sed-on-linux-the-basics\/#primaryimage"},"thumbnailUrl":"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-42.png","keywords":["how to use the sed command","How to use the stream editor on linux","Sed tool in Linux"],"articleSection":["Linux Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/draculaservers.com\/tutorials\/stream-editor-sed-on-linux-the-basics\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/draculaservers.com\/tutorials\/stream-editor-sed-on-linux-the-basics\/","url":"https:\/\/draculaservers.com\/tutorials\/stream-editor-sed-on-linux-the-basics\/","name":"Stream Editor (SED) on Linux: The Basics - Dracula Servers Tutorials","isPartOf":{"@id":"https:\/\/draculaservers.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/draculaservers.com\/tutorials\/stream-editor-sed-on-linux-the-basics\/#primaryimage"},"image":{"@id":"https:\/\/draculaservers.com\/tutorials\/stream-editor-sed-on-linux-the-basics\/#primaryimage"},"thumbnailUrl":"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-42.png","datePublished":"2024-06-25T10:00:03+00:00","dateModified":"2024-08-04T20:25:50+00:00","description":"The\u00a0sed\u00a0command is a powerful and versatile tool in Unix-like systems used for parsing and transforming text from a stream or a file.","breadcrumb":{"@id":"https:\/\/draculaservers.com\/tutorials\/stream-editor-sed-on-linux-the-basics\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/draculaservers.com\/tutorials\/stream-editor-sed-on-linux-the-basics\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/draculaservers.com\/tutorials\/stream-editor-sed-on-linux-the-basics\/#primaryimage","url":"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-42.png","contentUrl":"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-42.png","width":1280,"height":720,"caption":"Stream Editor (SED): The Basics"},{"@type":"BreadcrumbList","@id":"https:\/\/draculaservers.com\/tutorials\/stream-editor-sed-on-linux-the-basics\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/draculaservers.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Stream Editor (SED) on Linux: The Basics"}]},{"@type":"WebSite","@id":"https:\/\/draculaservers.com\/tutorials\/#website","url":"https:\/\/draculaservers.com\/tutorials\/","name":"Dracula Servers Tutorials","description":"Dedicated Servers","publisher":{"@id":"https:\/\/draculaservers.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/draculaservers.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/draculaservers.com\/tutorials\/#organization","name":"Dracula Servers","url":"https:\/\/draculaservers.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/draculaservers.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2016\/06\/dracula_full_logo_smaller.png","contentUrl":"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2016\/06\/dracula_full_logo_smaller.png","width":1625,"height":200,"caption":"Dracula Servers"},"image":{"@id":"https:\/\/draculaservers.com\/tutorials\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/draculaservers.com\/tutorials\/#\/schema\/person\/ac89d0281f4fb596bfaa0bc1e746c8a6","name":"Abdul Mannan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2809442d44177cab4f90e1d9b3295560462063881ca1374b6d597d8f0b48fc21?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2809442d44177cab4f90e1d9b3295560462063881ca1374b6d597d8f0b48fc21?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2809442d44177cab4f90e1d9b3295560462063881ca1374b6d597d8f0b48fc21?s=96&d=mm&r=g","caption":"Abdul Mannan"},"description":"An individual trying to decipher the enigmas of technology by the sheer driving force of curiosity. Interested in learning new skills and being better at those skills than the lot."}]}},"_links":{"self":[{"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/posts\/3467","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/comments?post=3467"}],"version-history":[{"count":1,"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/posts\/3467\/revisions"}],"predecessor-version":[{"id":3470,"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/posts\/3467\/revisions\/3470"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/media\/3469"}],"wp:attachment":[{"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/media?parent=3467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/categories?post=3467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/tags?post=3467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}