{"id":286,"date":"2010-11-23T09:49:04","date_gmt":"2010-11-23T09:49:04","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2010\/11\/23\/unix-sed-quick-reference\/"},"modified":"2019-10-20T04:20:18","modified_gmt":"2019-10-20T04:20:18","slug":"unix-sed-quick-reference","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/unix-sed-quick-reference\/","title":{"rendered":"Sed command Web References &#038; Cheatsheet"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4353\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2010\/11\/unix-sed-quick-reference.png\" alt=\"unix-sed-quick-reference\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2010\/11\/unix-sed-quick-reference.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2010\/11\/unix-sed-quick-reference-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\">UNIX SED Introduction<\/span><\/span><\/span><\/span><\/strong><\/p>\n<p class=\"MsoListParagraphCxSpFirst\" style=\"text-indent: -0.25in; margin: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1;\"><span style=\"color: #000000;\"><span style=\"font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;\"><span style=\"mso-list: Ignore;\"><span style=\"font-size: small;\">\u00b7<\/span> <\/span><\/span><span style=\"font-family: Calibri; font-size: small;\">Sed is a \u201cnon-interactive\u201d stream-oriented editor. Since its an \u201cnon-interactive\u201d it can be used to automate editing.<\/span><\/span><\/p>\n<p class=\"MsoListParagraphCxSpMiddle\" style=\"text-indent: -0.25in; margin: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1;\"><span style=\"color: #000000;\"><span style=\"font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;\"><span style=\"mso-list: Ignore;\"><span style=\"font-size: small;\">\u00b7<\/span> <\/span><\/span><span style=\"font-family: Calibri; font-size: small;\">This allows you to edit multiple files, or to perform common editing operations without opening VI or emacs.<\/span><\/span><\/p>\n<p class=\"MsoListParagraphCxSpMiddle\" style=\"text-indent: -0.25in; margin: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1;\"><span style=\"color: #000000;\"><span style=\"font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;\"><span style=\"mso-list: Ignore;\"><span style=\"font-size: small;\">\u00b7<\/span> <\/span><\/span><span style=\"font-family: Calibri; font-size: small;\">Sed reads from a file or from its standard input and outputs to its standard output.<\/span><\/span><\/p>\n<p class=\"MsoListParagraphCxSpLast\" style=\"text-indent: -0.25in; margin: 0in 0in 10pt 0.5in; mso-list: l0 level1 lfo1;\"><span style=\"color: #000000;\"><span style=\"font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;\"><span style=\"mso-list: Ignore;\"><span style=\"font-size: small;\">\u00b7<\/span> <\/span><\/span><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\"> Sed has two buffers which are called pattern buffer and hold buffer. Both are initially empty.<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\"><span style=\"color: #000000;\">UNIX Sed Working Method<\/span><\/span><\/span><\/span><\/strong><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-family: Calibri; color: #000000; font-size: small;\">This is called as one execution cycle. Cycle continues till end of file\/input is reached.<\/span><\/p>\n<p class=\"MsoListParagraphCxSpFirst\" style=\"text-indent: -0.25in; margin: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo2;\"><span style=\"color: #000000;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"mso-list: Ignore;\"><span style=\"font-family: Calibri; font-size: small;\">1.<\/span> <\/span><\/span><span style=\"font-family: Calibri; font-size: small;\">Read a entire line from stdin\/file.<\/span><\/span><\/p>\n<p class=\"MsoListParagraphCxSpMiddle\" style=\"text-indent: -0.25in; margin: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo2;\"><span style=\"color: #000000;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"mso-list: Ignore;\"><span style=\"font-family: Calibri; font-size: small;\">2.<\/span> <\/span><\/span><span style=\"font-family: Calibri; font-size: small;\">Removes any trailing newline.<\/span><\/span><\/p>\n<p class=\"MsoListParagraphCxSpMiddle\" style=\"text-indent: -0.25in; margin: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo2;\"><span style=\"color: #000000;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"mso-list: Ignore;\"><span style=\"font-family: Calibri; font-size: small;\">3.<\/span> <\/span><\/span><span style=\"font-family: Calibri; font-size: small;\">Places the line, in its pattern buffer.<\/span><\/span><\/p>\n<p class=\"MsoListParagraphCxSpMiddle\" style=\"text-indent: -0.25in; margin: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo2;\"><span style=\"color: #000000;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"mso-list: Ignore;\"><span style=\"font-family: Calibri; font-size: small;\">4.<\/span> <\/span><\/span><span style=\"font-family: Calibri; font-size: small;\">Modify the pattern buffer according to the supplied commands<\/span><\/span><\/p>\n<p class=\"MsoListParagraphCxSpLast\" style=\"text-indent: -0.25in; margin: 0in 0in 10pt 0.5in; mso-list: l1 level1 lfo2;\"><span style=\"color: #000000;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"mso-list: Ignore;\"><span style=\"font-family: Calibri; font-size: small;\">5.<\/span> <\/span><\/span><span style=\"font-family: Calibri; font-size: small;\">Print the pattern buffer to stdout.<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\"><span style=\"color: #000000;\">Printing Operation in Sed<\/span><\/span><\/span><\/span><\/strong><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-family: Calibri; color: #000000; font-size: small;\">Linux Sed command allows you to print only specific lines based on the line number or pattern matches. <strong style=\"mso-bidi-font-weight: normal;\">\u201cp\u201d <\/strong>is a command for printing the data from the pattern buffer.<\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\">Syntax:<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\"># sed -n &#8216;ADDRESS&#8217;p filename<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt 0.5in;\"><span style=\"color: #000000;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"line-height: 115%;\"># sed -n &#8216;\/PATTERN\/p&#8217; filename<\/span><\/em><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-family: Calibri; color: #000000; font-size: small;\">Create the txt file <strong style=\"mso-bidi-font-weight: normal;\">sample.txt<\/strong> that will be used in all examples below.<\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\"># cat sample.txt<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\">1. Linux &#8211; Sysadmin, Scripting etc.<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\">2. Databases &#8211; Oracle, mySQL etc.<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\">3. Hardware<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\">4. Security (Firewall, Network, Online Security etc)<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\">5. Storage<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\">6. Cool gadgets and websites<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\">7. Productivity (Too many technologies to explore)<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\">8. Website Design<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\">9. Software Development<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"line-height: 115%;\"><span style=\"color: #000000;\">10.Windows- Sysadmin, reboot etc.<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\"><span style=\"color: #000000;\">Sed Address Format 1: NUMBER<\/span><\/span><\/span><\/span><\/strong><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-family: Calibri; color: #000000; font-size: small;\">This will only match Nth line in the input.<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\"><span style=\"color: #000000;\">#sed \u2013n \u2018N\u2019p filename<\/span><\/span><\/span><\/strong><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-family: Calibri; color: #000000; font-size: small;\">For example, 3p prints 3<sup>rd<\/sup> line of the input file sample.txt as below<\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\"># sed -n &#8216;3&#8217;p thegeekstuff.txt<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt 0.5in;\"><span style=\"color: #000000;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"line-height: 115%;\">3. Hardware<\/span><\/em> <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\"><span style=\"color: #000000;\">Sed Address Format 2: NUMBER1~NUMBER2<\/span><\/span><\/span><\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">M~N with \u201cp\u201d command prints every Nth line starting from line M.<br \/>\n<\/span><strong><br \/>\n<strong><span style=\"color: #000000;\"># sed -n \u2018M~N\u2019p filename<\/span><\/strong><\/strong><\/p>\n<p><span style=\"color: #000000;\">For example, 3~2p prints every 2nd line starting from 3rd line as shown below.<\/span><\/p>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\"># sed -n '3~2'p thegeekstuff.txt<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">3. Hardware<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">5. Storage<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">7. Productivity (Too many technologies to explore)<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">9. Software Development<\/span><\/span><\/em><\/pre>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 10pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-outline-level: 3;\"><strong><span style=\"text-decoration: underline;\"><span style=\"mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\"><span style=\"color: #000000;\">Sed Address Format 3: START,END<\/span><\/span><\/span><\/span><\/span><\/strong><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 10pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;\"><span style=\"mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"font-family: Calibri; color: #000000; font-size: small;\">M,N with \u201cp\u201d command prints Mth line to Nth line.<br \/>\n<\/span><strong><br \/>\n<span style=\"font-family: Calibri; color: #000000; font-size: small;\"># sed -n \u2018M,N\u2019p filename<\/span><\/strong><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 10pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;\"><span style=\"mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\"><span style=\"color: #000000;\">For example, 4,8p prints from 4th line to 8th line from input file thegeekstuff.txt<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\"># sed -n &#8216;4,8&#8217;p thegeekstuff.txt<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\">4. Security (Firewall, Network, Online Security etc)<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\">5. Storage<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\">6. Cool gadgets and websites<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\">7. Productivity (Too many technologies to explore)<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\">8. Website Design<\/span><\/em><\/p>\n<h3 style=\"margin: auto 0in;\"><span style=\"text-decoration: underline;\"><span style=\"color: #000000;\">Sed Address Format 4: \u2018$\u2019 Last Line<\/span><\/span><\/h3>\n<p><span style=\"color: #000000;\">$ with \u201cp\u201d command matches only the last line from the input.<br \/>\n<\/span><strong><br \/>\n<strong><span style=\"color: #000000;\"># sed -n \u2018$\u2019p filename<\/span><\/strong><\/strong><\/p>\n<p><span style=\"color: #000000;\">For example, $p prints only the last line as shown below.<\/span><\/p>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\"># sed -n '\n\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">10.Windows- Sysadmin, reboot etc.<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-family: Courier New; font-size: x-small;\">&nbsp;<\/span><\/em><\/pre>\n<h3 style=\"margin: auto 0in;\"><span style=\"text-decoration: underline;\"><span style=\"color: #000000;\">Sed Address Format 5: NUMBER,$<\/span><\/span><\/h3>\n<p><span style=\"color: #000000;\">N,$ with \u201cp\u201d command prints from Nth line to end of file.<br \/>\n<\/span><strong><br \/>\n<strong><span style=\"color: #000000;\"># sed -n \u2018N,$p\u2019 filename<\/span><\/strong><\/strong><\/p>\n<p><span style=\"color: #000000;\">For example 4,$p prints from 4th line to end of file.<\/span><\/p>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\"># sed -n '4,$p' thegeekstuff.txt<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">4. Security (Firewall, Network, Online Security etc)<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">5. Storage<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">6. Cool gadgets and websites<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">7. Productivity (Too many technologies to explore)<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">8. Website Design<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">9. Software Development<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-family: Courier New; font-size: x-small;\">10.Windows- Sysadmin, reboot etc.<\/span><\/em><\/pre>\n<h3 style=\"margin: auto 0in;\"><span style=\"text-decoration: underline;\"><span style=\"color: #000000;\">Sed Pattern Format 1: PATTERN<\/span><\/span><\/h3>\n<p><span style=\"color: #000000;\">PATTERN could be unix regular expression. The below command prints only the line which matches the given pattern.<br \/>\n<\/span><strong><br \/>\n<strong><span style=\"color: #000000;\"># sed -n \/PATTERN\/p filename<\/span><\/strong><\/strong><\/p>\n<p><span style=\"color: #000000;\">For example, following prints the line only which matches the pattern \u201cSysadmin\u201d.<\/span><\/p>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\"># sed -n \/Sysadmin\/p thegeekstuff.txt<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">1. Linux - Sysadmin, Scripting etc.<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-family: Courier New; font-size: x-small;\">10.Windows- Sysadmin, reboot etc.<\/span><\/em><\/pre>\n<h3 style=\"margin: auto 0in;\"><span style=\"text-decoration: underline;\"><span style=\"color: #000000;\">Sed Pattern Format 2: \/PATTERN\/,ADDRESS<\/span><\/span><\/h3>\n<p><span style=\"color: #000000;\"><strong># sed -n \u2018\/PATTERN\/,Np\u2019 filename<\/strong><\/span><\/p>\n<p><span style=\"color: #000000;\">For example, following prints lines which matches the pattern to Nth line, from input. 3rd line matches the pattern \u201cHardware\u201d, so it prints from 3rd line to 6th line.<\/span><\/p>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\"># sed -n '\/Hardware\/,6p' thegeekstuff.txt<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">3. Hardware<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">4. Security (Firewall, Network, Online Security etc)<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">5. Storage<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">6. Cool gadgets and websites<\/span><\/span><\/em><\/pre>\n<h3 style=\"margin: auto 0in;\"><span style=\"text-decoration: underline;\"><span style=\"color: #000000;\">Sed Pattern Format 3: ADDRESS,\/PATTERN\/<\/span><\/span><\/h3>\n<p><span style=\"color: #000000;\">It prints from the Nth line of the input, to the line which matches the pattern. If the pattern doesnt match, it prints upto end of the input.<br \/>\n<\/span><strong><br \/>\n<strong><span style=\"color: #000000;\"># sed -n \u2018N,\/PATTERN\/p\u2019 filename<\/span><\/strong><\/strong><\/p>\n<p><span style=\"color: #000000;\">For example, 4th line matches the pattern \u201cSecurity\u201d, so it prints from 3rd line to 4th line.<\/span><\/p>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\"># sed -n '3,\/Security\/p' thegeekstuff.txt<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">3. Hardware<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-family: Courier New; font-size: x-small;\">4. Security (Firewall, Network, Online Security etc)<\/span><\/em><\/pre>\n<h3 style=\"margin: auto 0in;\"><span style=\"text-decoration: underline;\"><span style=\"color: #000000;\">Sed Pattern Format 4: \/PATTERN\/,$<\/span><\/span><\/h3>\n<p><span style=\"color: #000000;\">It prints from the line matches the given pattern to end of file.<br \/>\n<\/span><strong><br \/>\n<strong><span style=\"color: #000000;\"># sed -n \u2018\/PATTERN\/,$p\u2019 filename<\/span><\/strong><\/strong><\/p>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\"># sed -n '\/Website\/,$p' thegeekstuff.txt<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">8. Website Design<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">9. Software Development<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-family: Courier New; font-size: x-small;\">10.Windows- Sysadmin, reboot etc.<\/span><\/em><\/pre>\n<h3 style=\"margin: auto 0in;\"><span style=\"text-decoration: underline;\"><span style=\"color: #000000;\">Sed Pattern Format 5: \/PATTERN\/,+N<\/span><\/span><\/h3>\n<p><span style=\"color: #000000;\">It prints the lines which matches the pattern and next N lines following the matched line.<br \/>\n<\/span><strong><br \/>\n<strong><span style=\"color: #000000;\"># sed -n \u2018\/PATTERN\/,+Np\u2019 filename<\/span><\/strong><\/strong><\/p>\n<p><span style=\"color: #000000;\">For example, following prints the 5th line which matches the pattern \/Storage\/ and next two lines following \/Storage\/.<\/span><\/p>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\"># sed -n '\/Storage\/,+2p' thegeekstuff.txt<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">5. Storage<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">6. Cool gadgets and websites<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-family: Courier New; font-size: x-small;\">7. Productivity (Too many technologies to explore)<\/span><\/em><\/pre>\n<h3 style=\"margin: auto 0in;\"><span style=\"text-decoration: underline;\"><span style=\"color: #000000;\">Sed Pattern Format 6: \/PATTERN\/,\/PATTERN\/<\/span><\/span><\/h3>\n<p><span style=\"color: #000000;\">Prints the section of file between two regular expression (including the matched line ).<br \/>\n<\/span><strong><br \/>\n<strong><span style=\"color: #000000;\"># sed -n \u2018\/P1\/,\/P2\/p\u2019 filename<\/span><\/strong><\/strong><\/p>\n<p><span style=\"color: #000000;\">For example, 5th line matches \u201cStorage\u201d and 8th line matches \u201cDesign\u201d, so it prints 5th to 8th.<\/span><\/p>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\"># sed -n '\/Storage\/,\/Design\/p' thegeekstuff.txt<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">5. Storage<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">6. Cool gadgets and websites<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Courier New;\">7. Productivity (Too many technologies to explore)<\/span><\/span><\/em><\/pre>\n<pre style=\"margin-left: 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-family: Courier New; font-size: x-small;\">8. Website Design<\/span><\/em><\/pre>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"line-height: 115%; font-size: 12pt;\"><span style=\"font-family: Calibri;\"><span style=\"color: #000000;\">Delete File Lines Using Address and pattern in Sed<\/span><\/span><\/span><\/span><\/strong><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"line-height: 115%; font-size: 12pt;\"><span style=\"font-family: Calibri;\"><span style=\"color: #000000;\">\u201cp\u201d command prints the buffer (Remember to use \u201c-n\u201d option with \u201cp\u201d)<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"line-height: 115%; font-size: 12pt;\"><span style=\"font-family: Calibri;\"><span style=\"color: #000000;\">\u201cd\u201d command is just opposite, it\u2019s for deletion. \u201cd\u201d will delete the pattern space buffer and immediately starts the next cycle.<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\">Syntax:<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\"># sed 'ADDRESS'd filename<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"line-height: 115%;\"><span style=\"color: #000000;\"># sed \/PATTERN\/d filename<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\">Delete the Nth line.<\/span><\/span><\/span><\/span><\/span><\/strong><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\">\u201cNd\u201d delete the Nth line and prints the other lines.<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\">For example, 3d deletes 3<sup>rd<\/sup> line and prints other lines.<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\"> <em style=\"mso-bidi-font-style: normal;\">$sed 3d sample.txt<\/em><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\">Delete Starting from 3<sup>rd<\/sup> line and every 2<sup>nd<\/sup> line from there.<\/span><\/span><\/span><\/span><\/span><\/strong><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\"> <em style=\"mso-bidi-font-style: normal;\">$sed \u20183~2d\u2019 sample.txt<\/em><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\">Delete from 4ht to 8<sup>th<\/sup> line from file<\/span><\/span><\/strong><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\"> <em style=\"mso-bidi-font-style: normal;\">$sed \u20184,8d\u2019 sample.txt<\/em><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\">Delete the last line from input<\/span><\/span><\/span><\/span><\/span><\/strong><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\"> <em style=\"mso-bidi-font-style: normal;\">$sed \u2018$d\u2019 sample.txt<\/em><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\">Delete the line which matches the given pattern from input<\/span><\/span><\/strong><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\"> <em style=\"mso-bidi-font-style: normal;\">$sed \/Sysadmin\/d sample.txt <\/em><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\">Delete the line from which matches the given pattern to end of the file<\/span><\/span><\/span><\/span><\/span><\/strong><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\"> <em style=\"mso-bidi-font-style: normal;\">$sed \u2018\/Website\/ ,$d\u2019 sample.txt<\/em><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\">Delete the line from which matches the given pattern and 2 lines next to that<\/span><\/span><\/span><\/span><\/span><\/strong><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\"> <em style=\"mso-bidi-font-style: normal;\">$sed \u2018Storage\/ ,+2d\u2019 sample.txt<\/em><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\">Delete blank line from a file using sed.<\/span><\/span><\/span><\/span><\/span><\/strong><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\"> $sed \u2018\/^$\/d\u2019 sample.txt<\/span><\/span><\/em><\/p>\n<p>p thegeekstuff.txt<\/span><\/span><\/em><\/p>\n<pre wp-pre-tag-6=\"\"><\/pre>\n<pre wp-pre-tag-7=\"\"><\/pre>\n<h3 style=\"margin: auto 0in;\"><span style=\"text-decoration: underline;\"><span style=\"color: #000000;\">Sed Address Format 5: NUMBER,$<\/span><\/span><\/h3>\n<p><span style=\"color: #000000;\">N,$ with \u201cp\u201d command prints from Nth line to end of file.<br \/>\n<\/span><strong><br \/>\n<strong><span style=\"color: #000000;\"># sed -n \u2018N,$p\u2019 filename<\/span><\/strong><\/strong><\/p>\n<p><span style=\"color: #000000;\">For example 4,$p prints from 4th line to end of file.<\/span><\/p>\n<pre wp-pre-tag-8=\"\"><\/pre>\n<pre wp-pre-tag-9=\"\"><\/pre>\n<pre wp-pre-tag-10=\"\"><\/pre>\n<pre wp-pre-tag-11=\"\"><\/pre>\n<pre wp-pre-tag-12=\"\"><\/pre>\n<pre wp-pre-tag-13=\"\"><\/pre>\n<pre wp-pre-tag-14=\"\"><\/pre>\n<pre wp-pre-tag-15=\"\"><\/pre>\n<h3 style=\"margin: auto 0in;\"><span style=\"text-decoration: underline;\"><span style=\"color: #000000;\">Sed Pattern Format 1: PATTERN<\/span><\/span><\/h3>\n<p><span style=\"color: #000000;\">PATTERN could be unix regular expression. The below command prints only the line which matches the given pattern.<br \/>\n<\/span><strong><br \/>\n<strong><span style=\"color: #000000;\"># sed -n \/PATTERN\/p filename<\/span><\/strong><\/strong><\/p>\n<p><span style=\"color: #000000;\">For example, following prints the line only which matches the pattern \u201cSysadmin\u201d.<\/span><\/p>\n<pre wp-pre-tag-16=\"\"><\/pre>\n<pre wp-pre-tag-17=\"\"><\/pre>\n<pre wp-pre-tag-18=\"\"><\/pre>\n<h3 style=\"margin: auto 0in;\"><span style=\"text-decoration: underline;\"><span style=\"color: #000000;\">Sed Pattern Format 2: \/PATTERN\/,ADDRESS<\/span><\/span><\/h3>\n<p><span style=\"color: #000000;\"><strong># sed -n \u2018\/PATTERN\/,Np\u2019 filename<\/strong><\/span><\/p>\n<p><span style=\"color: #000000;\">For example, following prints lines which matches the pattern to Nth line, from input. 3rd line matches the pattern \u201cHardware\u201d, so it prints from 3rd line to 6th line.<\/span><\/p>\n<pre wp-pre-tag-19=\"\"><\/pre>\n<pre wp-pre-tag-20=\"\"><\/pre>\n<pre wp-pre-tag-21=\"\"><\/pre>\n<pre wp-pre-tag-22=\"\"><\/pre>\n<pre wp-pre-tag-23=\"\"><\/pre>\n<h3 style=\"margin: auto 0in;\"><span style=\"text-decoration: underline;\"><span style=\"color: #000000;\">Sed Pattern Format 3: ADDRESS,\/PATTERN\/<\/span><\/span><\/h3>\n<p><span style=\"color: #000000;\">It prints from the Nth line of the input, to the line which matches the pattern. If the pattern doesnt match, it prints upto end of the input.<br \/>\n<\/span><strong><br \/>\n<strong><span style=\"color: #000000;\"># sed -n \u2018N,\/PATTERN\/p\u2019 filename<\/span><\/strong><\/strong><\/p>\n<p><span style=\"color: #000000;\">For example, 4th line matches the pattern \u201cSecurity\u201d, so it prints from 3rd line to 4th line.<\/span><\/p>\n<pre wp-pre-tag-24=\"\"><\/pre>\n<pre wp-pre-tag-25=\"\"><\/pre>\n<pre wp-pre-tag-26=\"\"><\/pre>\n<h3 style=\"margin: auto 0in;\"><span style=\"text-decoration: underline;\"><span style=\"color: #000000;\">Sed Pattern Format 4: \/PATTERN\/,$<\/span><\/span><\/h3>\n<p><span style=\"color: #000000;\">It prints from the line matches the given pattern to end of file.<br \/>\n<\/span><strong><br \/>\n<strong><span style=\"color: #000000;\"># sed -n \u2018\/PATTERN\/,$p\u2019 filename<\/span><\/strong><\/strong><\/p>\n<pre wp-pre-tag-27=\"\"><\/pre>\n<pre wp-pre-tag-28=\"\"><\/pre>\n<pre wp-pre-tag-29=\"\"><\/pre>\n<pre wp-pre-tag-30=\"\"><\/pre>\n<h3 style=\"margin: auto 0in;\"><span style=\"text-decoration: underline;\"><span style=\"color: #000000;\">Sed Pattern Format 5: \/PATTERN\/,+N<\/span><\/span><\/h3>\n<p><span style=\"color: #000000;\">It prints the lines which matches the pattern and next N lines following the matched line.<br \/>\n<\/span><strong><br \/>\n<strong><span style=\"color: #000000;\"># sed -n \u2018\/PATTERN\/,+Np\u2019 filename<\/span><\/strong><\/strong><\/p>\n<p><span style=\"color: #000000;\">For example, following prints the 5th line which matches the pattern \/Storage\/ and next two lines following \/Storage\/.<\/span><\/p>\n<pre wp-pre-tag-31=\"\"><\/pre>\n<pre wp-pre-tag-32=\"\"><\/pre>\n<pre wp-pre-tag-33=\"\"><\/pre>\n<pre wp-pre-tag-34=\"\"><\/pre>\n<h3 style=\"margin: auto 0in;\"><span style=\"text-decoration: underline;\"><span style=\"color: #000000;\">Sed Pattern Format 6: \/PATTERN\/,\/PATTERN\/<\/span><\/span><\/h3>\n<p><span style=\"color: #000000;\">Prints the section of file between two regular expression (including the matched line ).<br \/>\n<\/span><strong><br \/>\n<strong><span style=\"color: #000000;\"># sed -n \u2018\/P1\/,\/P2\/p\u2019 filename<\/span><\/strong><\/strong><\/p>\n<p><span style=\"color: #000000;\">For example, 5th line matches \u201cStorage\u201d and 8th line matches \u201cDesign\u201d, so it prints 5th to 8th.<\/span><\/p>\n<pre wp-pre-tag-35=\"\"><\/pre>\n<pre wp-pre-tag-36=\"\"><\/pre>\n<pre wp-pre-tag-37=\"\"><\/pre>\n<pre wp-pre-tag-38=\"\"><\/pre>\n<pre wp-pre-tag-39=\"\"><\/pre>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"line-height: 115%; font-size: 12pt;\"><span style=\"font-family: Calibri;\"><span style=\"color: #000000;\">Delete File Lines Using Address and pattern in Sed<\/span><\/span><\/span><\/span><\/strong><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"line-height: 115%; font-size: 12pt;\"><span style=\"font-family: Calibri;\"><span style=\"color: #000000;\">\u201cp\u201d command prints the buffer (Remember to use \u201c-n\u201d option with \u201cp\u201d)<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"line-height: 115%; font-size: 12pt;\"><span style=\"font-family: Calibri;\"><span style=\"color: #000000;\">\u201cd\u201d command is just opposite, it\u2019s for deletion. \u201cd\u201d will delete the pattern space buffer and immediately starts the next cycle.<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\">Syntax:<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"line-height: normal; margin: 0in 0in 0pt 0.5in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"color: #000000;\"># sed &#8216;ADDRESS&#8217;d filename<\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt 0.5in;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"line-height: 115%;\"><span style=\"color: #000000;\"># sed \/PATTERN\/d filename<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\">Delete the Nth line.<\/span><\/span><\/span><\/span><\/span><\/strong><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\">\u201cNd\u201d delete the Nth line and prints the other lines.<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\">For example, 3d deletes 3<sup>rd<\/sup> line and prints other lines.<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\"> <em style=\"mso-bidi-font-style: normal;\">$sed 3d sample.txt<\/em><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\">Delete Starting from 3<sup>rd<\/sup> line and every 2<sup>nd<\/sup> line from there.<\/span><\/span><\/span><\/span><\/span><\/strong><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\"> <em style=\"mso-bidi-font-style: normal;\">$sed \u20183~2d\u2019 sample.txt<\/em><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\">Delete from 4ht to 8<sup>th<\/sup> line from file<\/span><\/span><\/strong><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\"> <em style=\"mso-bidi-font-style: normal;\">$sed \u20184,8d\u2019 sample.txt<\/em><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\">Delete the last line from input<\/span><\/span><\/span><\/span><\/span><\/strong><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\"> <em style=\"mso-bidi-font-style: normal;\">$sed \u2018$d\u2019 sample.txt<\/em><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\">Delete the line which matches the given pattern from input<\/span><\/span><\/strong><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\"> <em style=\"mso-bidi-font-style: normal;\">$sed \/Sysadmin\/d sample.txt <\/em><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\">Delete the line from which matches the given pattern to end of the file<\/span><\/span><\/span><\/span><\/span><\/strong><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\"> <em style=\"mso-bidi-font-style: normal;\">$sed \u2018\/Website\/ ,$d\u2019 sample.txt<\/em><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\">Delete the line from which matches the given pattern and 2 lines next to that<\/span><\/span><\/span><\/span><\/span><\/strong><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\"> <em style=\"mso-bidi-font-style: normal;\">$sed \u2018Storage\/ ,+2d\u2019 sample.txt<\/em><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><strong style=\"mso-bidi-font-weight: normal;\"><span style=\"text-decoration: underline;\"><span style=\"mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;\"><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\">Delete blank line from a file using sed.<\/span><\/span><\/span><\/span><\/span><\/strong><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 10pt;\"><em style=\"mso-bidi-font-style: normal;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\"> $sed \u2018\/^$\/d\u2019 sample.txt<\/span><\/span><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>UNIX SED Introduction \u00b7 Sed is a \u201cnon-interactive\u201d stream-oriented editor. Since its an \u201cnon-interactive\u201d it can be used to automate editing. \u00b7 This allows you to edit multiple files, or&#8230; <\/p>\n","protected":false},"author":1,"featured_media":4353,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[4957],"tags":[4084,2540,938,4080,169,4081,4088,4086,4082,4085,4083,4087],"class_list":["post-286","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-introduction-of-unix-sed","tag-quick","tag-reference","tag-sed","tag-unix","tag-unix-sed","tag-unix-sed-command","tag-unix-sed-guide","tag-unix-sed-introduction","tag-unix-sed-overview","tag-unix-sed-working-method","tag-what-is-unix-sed"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=286"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/286\/revisions"}],"predecessor-version":[{"id":7247,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/286\/revisions\/7247"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/4353"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}