<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://performiq.com/kb/index.php?action=history&amp;feed=atom&amp;title=SED_Hints</id>
	<title>SED Hints - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://performiq.com/kb/index.php?action=history&amp;feed=atom&amp;title=SED_Hints"/>
	<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=SED_Hints&amp;action=history"/>
	<updated>2026-05-18T20:08:05Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.37.1</generator>
	<entry>
		<id>https://performiq.com/kb/index.php?title=SED_Hints&amp;diff=4695&amp;oldid=prev</id>
		<title>PeterHarding at 02:48, 17 December 2015</title>
		<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=SED_Hints&amp;diff=4695&amp;oldid=prev"/>
		<updated>2015-12-17T02:48:22Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 12:48, 17 December 2015&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l3&quot;&gt;Line 3:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 3:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;-------------------------------------------------------------------------------&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;-------------------------------------------------------------------------------&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Also see  regex.hints  for hints and tips of matching regular expressions&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Also see  regex.hints  for hints and tips of matching regular expressions&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>PeterHarding</name></author>
	</entry>
	<entry>
		<id>https://performiq.com/kb/index.php?title=SED_Hints&amp;diff=4694&amp;oldid=prev</id>
		<title>PeterHarding at 02:48, 17 December 2015</title>
		<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=SED_Hints&amp;diff=4694&amp;oldid=prev"/>
		<updated>2015-12-17T02:48:09Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 12:48, 17 December 2015&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;From - https://www.ict.griffith.edu.au/anthony/info/shell/sed.hints&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>PeterHarding</name></author>
	</entry>
	<entry>
		<id>https://performiq.com/kb/index.php?title=SED_Hints&amp;diff=4693&amp;oldid=prev</id>
		<title>PeterHarding: Created page with &quot; &lt;pre&gt;  ------------------------------------------------------------------------------- Also see  regex.hints  for hints and tips of matching regular expressions And sed 1 lin...&quot;</title>
		<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=SED_Hints&amp;diff=4693&amp;oldid=prev"/>
		<updated>2015-12-17T02:47:33Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; &amp;lt;pre&amp;gt;  ------------------------------------------------------------------------------- Also see  regex.hints  for hints and tips of matching regular expressions And sed 1 lin...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
Also see  regex.hints  for hints and tips of matching regular expressions&lt;br /&gt;
And sed 1 liners&lt;br /&gt;
  http://sed.sourceforge.net/sed1line.txt&lt;br /&gt;
Also examples from the gnu &amp;quot;info sed&amp;quot;&lt;br /&gt;
&lt;br /&gt;
------------------------------------------------------------------------------&lt;br /&gt;
Print specific lines&lt;br /&gt;
&lt;br /&gt;
print first line of file (emulates &amp;quot;head -1&amp;quot;)&lt;br /&gt;
  sed q&lt;br /&gt;
&lt;br /&gt;
print first 10 lines of file (emulates behavior of &amp;quot;head&amp;quot;)&lt;br /&gt;
  sed 10q&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
print the last line of a file (emulates &amp;quot;tail -1&amp;quot;)&lt;br /&gt;
  sed &amp;#039;$!d&amp;#039;                    # method 1&lt;br /&gt;
  sed -n &amp;#039;$p&amp;#039;                  # method 2&lt;br /&gt;
&lt;br /&gt;
print the next-to-the-last line of a file&lt;br /&gt;
  sed -e &amp;#039;$!{h;d;}&amp;#039; -e x              # for 1-line files, print blank line&lt;br /&gt;
  sed -e &amp;#039;1{$q;}&amp;#039; -e &amp;#039;$!{h;d;}&amp;#039; -e x  # for 1-line files, print the line&lt;br /&gt;
  sed -e &amp;#039;1{$d;}&amp;#039; -e &amp;#039;$!{h;d;}&amp;#039; -e x  # for 1-line files, print nothing&lt;br /&gt;
&lt;br /&gt;
print the last 2 lines of a file (emulates &amp;quot;tail -2&amp;quot;)&lt;br /&gt;
  sed &amp;#039;$!N;$!D&amp;#039;&lt;br /&gt;
&lt;br /&gt;
print the last 10 lines of a file (emulates &amp;quot;tail&amp;quot;)&lt;br /&gt;
  sed -e :a -e &amp;#039;$q;N;11,$D;ba&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
------------------------------------------------------------------------------&lt;br /&gt;
Delete between Markers AAAA and BBBB&lt;br /&gt;
&lt;br /&gt;
Inclusive delete (delete start and end)&lt;br /&gt;
  sed &amp;#039;/AAAA/,/BBBB/d&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Exclusive delete (output start and end)&lt;br /&gt;
  sed &amp;#039;1,/AAAA/p; /BBBB/,$p; d&amp;#039;&lt;br /&gt;
or&lt;br /&gt;
  sed &amp;#039;/AAAA/,/BBBB/{ /AAAA/p; /BBBB/p; d }&amp;#039;&lt;br /&gt;
&lt;br /&gt;
delete end but output start&lt;br /&gt;
  sed &amp;#039;/AAAA/p; /AAAA/,/BBBB/d&amp;#039;&lt;br /&gt;
or&lt;br /&gt;
  sed &amp;#039;/AAAA/,/BBBB/{ /AAAA/p; d }&amp;#039;&lt;br /&gt;
&lt;br /&gt;
delete start but output end&lt;br /&gt;
  sed &amp;#039;/AAAA/,/BBBB/{ /BBBB/p; d }&amp;#039;&lt;br /&gt;
or&lt;br /&gt;
  sed &amp;#039;/BBBB/p; /AAAA/,/BBBB/d }&amp;#039;&lt;br /&gt;
&lt;br /&gt;
See next...&lt;br /&gt;
&lt;br /&gt;
------------------------------------------------------------------------------&lt;br /&gt;
Print lines between markers AAAA to BBBB&lt;br /&gt;
&lt;br /&gt;
Including markers&lt;br /&gt;
  sed -n &amp;#039;/AAAA/,$p; /BBBB/q&amp;#039; file&lt;br /&gt;
&lt;br /&gt;
Excluding the end marker&lt;br /&gt;
  sed -n &amp;#039;/BBBB/q; /AAAA/,$p&amp;#039; file&lt;br /&gt;
or&lt;br /&gt;
  sed -n &amp;#039;/AAAA/,$p; /BBBB/Q&amp;#039; file&lt;br /&gt;
&lt;br /&gt;
Excluding both markers&lt;br /&gt;
  sed -n &amp;#039;/BBBB/q; 1,/AAAA/d; p&amp;#039; file&lt;br /&gt;
or&lt;br /&gt;
  sed &amp;#039;1,/AAAA/d; /BBBB/Q&amp;#039; file&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
Line numbers&lt;br /&gt;
&lt;br /&gt;
left aligned&lt;br /&gt;
  sed = file | sed &amp;#039;N;s/\n/\t/&amp;#039;&lt;br /&gt;
&lt;br /&gt;
right aligned&lt;br /&gt;
  sed = filename | sed &amp;#039;N; s/^/     /; s/ *\(.\{6,\}\)\n/\1  /&amp;#039;&lt;br /&gt;
&lt;br /&gt;
counting lines (&amp;quot;sed&amp;quot; only no &amp;quot;wc&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  sed -n &amp;#039;$=&amp;#039; file&lt;br /&gt;
&lt;br /&gt;
------------------------------------------------------------------------------&lt;br /&gt;
Delete ALL blank lines&lt;br /&gt;
  sed &amp;#039;/^$/d&amp;#039; file&lt;br /&gt;
&lt;br /&gt;
Delete multiple blank lines (paragraph separators)&lt;br /&gt;
  sed &amp;#039;/^$/{ N; /^\n$/D; }&amp;#039; file&lt;br /&gt;
or&lt;br /&gt;
  sed &amp;#039;/./,/^$/!d&amp;#039; file&lt;br /&gt;
&lt;br /&gt;
===============================================================================&lt;br /&gt;
Programming with sed....&lt;br /&gt;
&lt;br /&gt;
------------------------------------------------------------------------------&lt;br /&gt;
Delimiting &amp;quot;sed&amp;quot; Delimetors (also see next)&lt;br /&gt;
&lt;br /&gt;
Say you want to search for a path name that contains slashes `/&amp;#039;&lt;br /&gt;
unfortunatally these are the sed regular expresion delimiters so you&lt;br /&gt;
need to escape the slashes before you can search for it. This is not as&lt;br /&gt;
easy as it sounds.&lt;br /&gt;
&lt;br /&gt;
old_path=&amp;quot;/some/path/to/look/for&amp;quot;&lt;br /&gt;
new_path=&amp;quot;/some/path/to/look/for&amp;quot;&lt;br /&gt;
&lt;br /&gt;
old_path=`echo &amp;quot;$old_path&amp;quot; | sed &amp;#039;s/\//\\\\\//g&amp;#039;`&lt;br /&gt;
new_path=`echo &amp;quot;$new_path&amp;quot; | sed &amp;#039;s/\//\\\\\//g&amp;#039;`&lt;br /&gt;
&lt;br /&gt;
sed &amp;#039;s&amp;#039;&amp;quot;$old_path&amp;quot;&amp;#039;/&amp;#039;&amp;quot;$new_path&amp;quot;&amp;#039;/g&amp;#039; $old_file &amp;gt; $new_file&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
Sed with arbatitry patterns&lt;br /&gt;
&lt;br /&gt;
   #!/bin/sh&lt;br /&gt;
   #  substitute {pattern} {replacement}&lt;br /&gt;
   #&lt;br /&gt;
   sed &amp;#039;s/&amp;#039;&amp;quot;$1&amp;quot;&amp;#039;/&amp;#039;&amp;quot;$2&amp;quot;&amp;#039;/g&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s OK provided you know for certain that $1 will never contain a &amp;quot;/&amp;quot;&lt;br /&gt;
or &amp;quot;\&amp;quot;, and $2 will never contain a &amp;quot;/&amp;quot;, &amp;quot;\&amp;quot; or &amp;quot;&amp;amp;&amp;quot;.  If $1 and $2 are&lt;br /&gt;
completely arbitrary you need to do something like:&lt;br /&gt;
&lt;br /&gt;
    pat=`echo &amp;quot;$1&amp;quot; | sed &amp;#039;s:[/\\]:\\&amp;amp;:g&amp;#039;`&lt;br /&gt;
    rep=`echo &amp;quot;$2&amp;quot; | sed &amp;#039;s:[/\\&amp;amp;]:\\&amp;amp;:g&amp;#039;`&lt;br /&gt;
    sed &amp;quot;s/$pat/$rep/g&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Is there a problem with  &amp;quot;&amp;quot;&amp;quot; or &amp;quot;`&amp;quot; in patterns?  -- seems not&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
Sed Programming Methology Example:&lt;br /&gt;
&lt;br /&gt;
This sed script grabs a &amp;#039;face&amp;#039; file (which always starts with a space or tab)&lt;br /&gt;
and repositions it correctly at the end of the mail header (denoted by a&lt;br /&gt;
absolutely blank line). NOTE the use of lables.&lt;br /&gt;
&lt;br /&gt;
  cat $FACE - $SIGNED | sed -n &amp;#039;&lt;br /&gt;
    # first collect the new face at the start of the input&lt;br /&gt;
    1 { s/^/X-Face:/; h; d; }&lt;br /&gt;
      /^[ \t]/{H;d;}&lt;br /&gt;
    # read the header; if X-face found just copy all&lt;br /&gt;
    : head&lt;br /&gt;
      /^X-Face:/ b body&lt;br /&gt;
      /^$/ b face&lt;br /&gt;
      p; n; b head&lt;br /&gt;
    # output a face at end of header&lt;br /&gt;
    :face&lt;br /&gt;
      x; p; g; p; n&lt;br /&gt;
    # just copy the rest of the file&lt;br /&gt;
    : body&lt;br /&gt;
      p; n; b body&lt;br /&gt;
  &amp;#039; | /lib/sendmail &amp;quot;$@&amp;quot;&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
Adding a newline to sed (just add return -- messy)&lt;br /&gt;
  bourne shells:&lt;br /&gt;
       sed &amp;#039;s/;$/; }\&lt;br /&gt;
       /&amp;#039; filename&lt;br /&gt;
&lt;br /&gt;
  Csh family:&lt;br /&gt;
       sed &amp;#039;s/;$/; }\\&lt;br /&gt;
       /&amp;#039; filename&lt;br /&gt;
&lt;br /&gt;
Of course you can always use a tr which is slower but neater&lt;br /&gt;
&lt;br /&gt;
      sed &amp;#039;s/;$/; }@/&amp;#039; | tr &amp;#039;@&amp;#039; &amp;#039;\012&amp;#039;&lt;br /&gt;
&lt;br /&gt;
GNU sed allows you to use \r  (for return)&lt;br /&gt;
But uses \n on the input side.  Do not use \n on output as that is &amp;#039;null&amp;#039;&lt;br /&gt;
&lt;br /&gt;
      sed &amp;#039;s/;$/; }\r/&amp;#039;&lt;br /&gt;
&lt;br /&gt;
In a similar way it allows the use of \t for tab.&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
Moving a line to the start of the file&lt;br /&gt;
EG&lt;br /&gt;
     something1                          this&lt;br /&gt;
     something2            ====&amp;gt;         something1&lt;br /&gt;
     this                                something2&lt;br /&gt;
     something3                          something3&lt;br /&gt;
&lt;br /&gt;
  sed -n &amp;#039;&lt;br /&gt;
    /this/!H                      # if no match append to hold space&lt;br /&gt;
    /this/{x; H; }                # found so exhange and append (prepend)&lt;br /&gt;
    ${g; s/\n//; p; }&amp;#039; &amp;lt;infile    # if last line get and print hold&lt;br /&gt;
OR&lt;br /&gt;
  sed &amp;#039;1,/this/{                  # until found&lt;br /&gt;
    /this/!{H; d; }               # if not it put in hold (no print)&lt;br /&gt;
    G; s-\n--; }&amp;#039; infile          # otherwise output hold&lt;br /&gt;
                                  # no match will continue print rest of file&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
Word Division -- sed and non-sed version&lt;br /&gt;
&lt;br /&gt;
    Name=`echo $DISPLAY | sed &amp;#039;s/:.*//&amp;#039;`&lt;br /&gt;
&lt;br /&gt;
can be done faster with&lt;br /&gt;
&lt;br /&gt;
    oldIFS=$IFS; IFS=.; set -- $DISPLAY; IFS=$oldIFS; Name=$1;&lt;br /&gt;
&lt;br /&gt;
no fork, totally internal to shell&lt;br /&gt;
&lt;br /&gt;
------------------------------------------------------------------------------&lt;br /&gt;
Increment the number given&lt;br /&gt;
&lt;br /&gt;
  sed -e &amp;#039;&lt;br /&gt;
    #Add zero to start if needed&lt;br /&gt;
    /^9*$/ s/^/0/&lt;br /&gt;
    # separate changing/unchanged digits with an x (and hold)&lt;br /&gt;
    s/.9*$/x&amp;amp;/&lt;br /&gt;
    h&lt;br /&gt;
    # increment digits&lt;br /&gt;
    s/^.*x//&lt;br /&gt;
    y/0123456789/1234567890/&lt;br /&gt;
    # merge unchanged with changed&lt;br /&gt;
    x&lt;br /&gt;
    s/x.*$//&lt;br /&gt;
    G&lt;br /&gt;
    s/\n//&lt;br /&gt;
    &amp;#039;&lt;br /&gt;
&lt;br /&gt;
Alturnative without using the hold buffer&lt;br /&gt;
&lt;br /&gt;
  sed -e &amp;#039;&lt;br /&gt;
    /[^0-9]/ d&lt;br /&gt;
&lt;br /&gt;
    # replace all leading 9s by _ (any non-digit could be used)&lt;br /&gt;
    :d&lt;br /&gt;
    s/9\(_*\)$/_\1/&lt;br /&gt;
    td&lt;br /&gt;
&lt;br /&gt;
    # incr last digit only.  The first line adds a most-significant&lt;br /&gt;
    # digit of 1 if we have to add a digit.&lt;br /&gt;
    #&lt;br /&gt;
    # The t commands are not necessary, but make the thing faster&lt;br /&gt;
&lt;br /&gt;
    s/^\(_*\)$/1\1/; tn&lt;br /&gt;
    s/8\(_*\)$/9\1/; tn&lt;br /&gt;
    s/7\(_*\)$/8\1/; tn&lt;br /&gt;
    s/6\(_*\)$/7\1/; tn&lt;br /&gt;
    s/5\(_*\)$/6\1/; tn&lt;br /&gt;
    s/4\(_*\)$/5\1/; tn&lt;br /&gt;
    s/3\(_*\)$/4\1/; tn&lt;br /&gt;
    s/2\(_*\)$/3\1/; tn&lt;br /&gt;
    s/1\(_*\)$/2\1/; tn&lt;br /&gt;
    s/0\(_*\)$/1\1/; tn&lt;br /&gt;
&lt;br /&gt;
    :n&lt;br /&gt;
    y/_/0/&lt;br /&gt;
    &amp;#039;&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
Count &amp;#039;a&amp;#039;s on a line&lt;br /&gt;
&lt;br /&gt;
  sed -e &amp;#039;&lt;br /&gt;
    # convert groups of ten to a higher order&lt;br /&gt;
    # The t and b are not necessary, but is faster&lt;br /&gt;
    t a&lt;br /&gt;
    : a;  s/aaaaaaaaaa/b/g; t b; b done&lt;br /&gt;
    : b;  s/bbbbbbbbbb/c/g; t c; b done&lt;br /&gt;
    : c;  s/cccccccccc/d/g; t d; b done&lt;br /&gt;
    : d;  s/dddddddddd/e/g; t e; b done&lt;br /&gt;
    : e;  s/eeeeeeeeee/f/g; t f; b done&lt;br /&gt;
    : f;  s/ffffffffff/g/g; t g; b done&lt;br /&gt;
    : g;  s/gggggggggg/h/g; t h; b done&lt;br /&gt;
    : h;  s/hhhhhhhhhh//g&lt;br /&gt;
    : done&lt;br /&gt;
&lt;br /&gt;
    # convert back to numbers&lt;br /&gt;
    : loop&lt;br /&gt;
    /a/! s/[b-h]*/&amp;amp;0/&lt;br /&gt;
    s/aaaaaaaaa/9/&lt;br /&gt;
    s/aaaaaaaa/8/&lt;br /&gt;
    s/aaaaaaa/7/&lt;br /&gt;
    s/aaaaaa/6/&lt;br /&gt;
    s/aaaaa/5/&lt;br /&gt;
    s/aaaa/4/&lt;br /&gt;
    s/aaa/3/&lt;br /&gt;
    s/aa/2/&lt;br /&gt;
    s/a/1/&lt;br /&gt;
&lt;br /&gt;
    # loop to do next digit&lt;br /&gt;
    y/bcdefgh/abcdefg/&lt;br /&gt;
    /[a-h]/ b loop&lt;br /&gt;
    &amp;#039; &lt;br /&gt;
&lt;br /&gt;
------------------------------------------------------------------------------&lt;br /&gt;
Reverse characters in a line&lt;br /&gt;
&lt;br /&gt;
  sed -e &amp;#039;&lt;br /&gt;
     # skip lines with lest than two characters&lt;br /&gt;
     /../! b&lt;br /&gt;
&lt;br /&gt;
     # Embed newlines at both ends&lt;br /&gt;
     # then slowly meove markers toward middle&lt;br /&gt;
     :x&lt;br /&gt;
     s/\(\n.\)\(.*\)\(.\n\)/\3\2\1/&lt;br /&gt;
     tx&lt;br /&gt;
&lt;br /&gt;
     # remove newline markers&lt;br /&gt;
     s/\n//g&lt;br /&gt;
     &amp;#039;&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Sed]]&lt;br /&gt;
[[Category:UNIX Tools]]&lt;/div&gt;</summary>
		<author><name>PeterHarding</name></author>
	</entry>
</feed>