<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>What is Unix sed Archives - scmGalaxy</title>
	<atom:link href="https://www.scmgalaxy.com/tutorials/tag/what-is-unix-sed/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.scmgalaxy.com/tutorials/tag/what-is-unix-sed/</link>
	<description>A Platform for Software Engineers</description>
	<lastBuildDate>Sat, 27 Feb 2021 09:53:51 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>
	<item>
		<title>Unix Sed Quick Reference</title>
		<link>https://www.scmgalaxy.com/tutorials/unix-sed-quick-reference/</link>
					<comments>https://www.scmgalaxy.com/tutorials/unix-sed-quick-reference/#respond</comments>
		
		<dc:creator><![CDATA[scmgalaxy K]]></dc:creator>
		<pubDate>Tue, 23 Nov 2010 09:49:04 +0000</pubDate>
				<category><![CDATA[Unix / Linux]]></category>
		<category><![CDATA[Introduction of Unix Sed]]></category>
		<category><![CDATA[Quick]]></category>
		<category><![CDATA[Reference]]></category>
		<category><![CDATA[Sed]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[Unix Sed]]></category>
		<category><![CDATA[Unix sed command]]></category>
		<category><![CDATA[Unix Sed Guide]]></category>
		<category><![CDATA[UNIX SED Introduction]]></category>
		<category><![CDATA[Unix Sed Overview]]></category>
		<category><![CDATA[UNIX Sed Working Method]]></category>
		<category><![CDATA[What is Unix sed]]></category>
		<guid isPermaLink="false">http://www.scmgalaxy.com/tutorials/2010/11/23/unix-sed-quick-reference/</guid>

					<description><![CDATA[<p>UNIX SED Introduction · Sed is a “non-interactive” stream-oriented editor. Since its an “non-interactive” it can be used to automate [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/unix-sed-quick-reference/">Unix Sed Quick Reference</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-4353" src="https://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.scmgalaxy.com/tutorials/wp-content/uploads/2010/11/unix-sed-quick-reference.png 600w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2010/11/unix-sed-quick-reference-300x200.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></p>
<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>
<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;">·</span> </span></span><span style="font-family: Calibri; font-size: small;">Sed is a “non-interactive” stream-oriented editor. Since its an “non-interactive” it can be used to automate editing.</span></span></p>
<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;">·</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>
<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;">·</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>
<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;">·</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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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;">“p” </strong>is a command for printing the data from the pattern buffer.</span></p>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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 –n ‘N’p filename</span></span></span></strong></p>
<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>
<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>
<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>
<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>
<p><span style="color: #000000;">M~N with “p” command prints every Nth line starting from line M.<br />
</span><strong><br />
<strong><span style="color: #000000;"># sed -n ‘M~N’p filename</span></strong></strong></p>
<p><span style="color: #000000;">For example, 3~2p prints every 2nd line starting from 3rd line as shown below.</span></p>
<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>
<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>
<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>
<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>
<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>
<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>
<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 “p” command prints Mth line to Nth line.<br />
</span><strong><br />
<span style="font-family: Calibri; color: #000000; font-size: small;"># sed -n ‘M,N’p filename</span></strong></span></p>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<h3 style="margin: auto 0in;"><span style="text-decoration: underline;"><span style="color: #000000;">Sed Address Format 4: ‘$’ Last Line</span></span></h3>
<p><span style="color: #000000;">$ with “p” command matches only the last line from the input.<br />
</span><strong><br />
<strong><span style="color: #000000;"># sed -n ‘$’p filename</span></strong></strong></p>
<p><span style="color: #000000;">For example, $p prints only the last line as shown below.</span></p>
<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 '$'p thegeekstuff.txt</span></span></em></pre>
<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>
<pre style="margin-left: 0.5in;"><em style="mso-bidi-font-style: normal;"><span style="font-family: Courier New; font-size: x-small;"> </span></em></pre>
<h3 style="margin: auto 0in;"><span style="text-decoration: underline;"><span style="color: #000000;">Sed Address Format 5: NUMBER,$</span></span></h3>
<p><span style="color: #000000;">N,$ with “p” command prints from Nth line to end of file.<br />
</span><strong><br />
<strong><span style="color: #000000;"># sed -n ‘N,$p’ filename</span></strong></strong></p>
<p><span style="color: #000000;">For example 4,$p prints from 4th line to end of file.</span></p>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<h3 style="margin: auto 0in;"><span style="text-decoration: underline;"><span style="color: #000000;">Sed Pattern Format 1: PATTERN</span></span></h3>
<p><span style="color: #000000;">PATTERN could be unix regular expression. The below command prints only the line which matches the given pattern.<br />
</span><strong><br />
<strong><span style="color: #000000;"># sed -n /PATTERN/p filename</span></strong></strong></p>
<p><span style="color: #000000;">For example, following prints the line only which matches the pattern “Sysadmin”.</span></p>
<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>
<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>
<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>
<h3 style="margin: auto 0in;"><span style="text-decoration: underline;"><span style="color: #000000;">Sed Pattern Format 2: /PATTERN/,ADDRESS</span></span></h3>
<p><span style="color: #000000;"><strong># sed -n ‘/PATTERN/,Np’ filename</strong></span></p>
<p><span style="color: #000000;">For example, following prints lines which matches the pattern to Nth line, from input. 3rd line matches the pattern “Hardware”, so it prints from 3rd line to 6th line.</span></p>
<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>
<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>
<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>
<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>
<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>
<h3 style="margin: auto 0in;"><span style="text-decoration: underline;"><span style="color: #000000;">Sed Pattern Format 3: ADDRESS,/PATTERN/</span></span></h3>
<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 />
</span><strong><br />
<strong><span style="color: #000000;"># sed -n ‘N,/PATTERN/p’ filename</span></strong></strong></p>
<p><span style="color: #000000;">For example, 4th line matches the pattern “Security”, so it prints from 3rd line to 4th line.</span></p>
<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>
<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>
<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>
<h3 style="margin: auto 0in;"><span style="text-decoration: underline;"><span style="color: #000000;">Sed Pattern Format 4: /PATTERN/,$</span></span></h3>
<p><span style="color: #000000;">It prints from the line matches the given pattern to end of file.<br />
</span><strong><br />
<strong><span style="color: #000000;"># sed -n ‘/PATTERN/,$p’ filename</span></strong></strong></p>
<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>
<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>
<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>
<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>
<h3 style="margin: auto 0in;"><span style="text-decoration: underline;"><span style="color: #000000;">Sed Pattern Format 5: /PATTERN/,+N</span></span></h3>
<p><span style="color: #000000;">It prints the lines which matches the pattern and next N lines following the matched line.<br />
</span><strong><br />
<strong><span style="color: #000000;"># sed -n ‘/PATTERN/,+Np’ filename</span></strong></strong></p>
<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>
<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>
<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>
<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>
<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>
<h3 style="margin: auto 0in;"><span style="text-decoration: underline;"><span style="color: #000000;">Sed Pattern Format 6: /PATTERN/,/PATTERN/</span></span></h3>
<p><span style="color: #000000;">Prints the section of file between two regular expression (including the matched line ).<br />
</span><strong><br />
<strong><span style="color: #000000;"># sed -n ‘/P1/,/P2/p’ filename</span></strong></strong></p>
<p><span style="color: #000000;">For example, 5th line matches “Storage” and 8th line matches “Design”, so it prints 5th to 8th.</span></p>
<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>
<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>
<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>
<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>
<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>
<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>
<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;">“p” command prints the buffer (Remember to use “-n” option with “p”)</span></span></span></p>
<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;">“d” command is just opposite, it’s for deletion. “d” will delete the pattern space buffer and immediately starts the next cycle.</span></span></span></p>
<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>
<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>
<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>
<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>
<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;">“Nd” delete the Nth line and prints the other lines.</span></span></span></span></p>
<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>
<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>
<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>
<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 ‘3~2d’ sample.txt</em></span></span></p>
<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>
<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 ‘4,8d’ sample.txt</em></span></span></p>
<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>
<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 ‘$d’ sample.txt</em></span></span></p>
<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>
<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>
<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>
<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 ‘/Website/ ,$d’ sample.txt</em></span></span></p>
<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>
<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 ‘Storage/ ,+2d’ sample.txt</em></span></span></p>
<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>
<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 ‘/^$/d’ sample.txt</span></span></em></p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/unix-sed-quick-reference/">Unix Sed Quick Reference</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/unix-sed-quick-reference/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
