<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
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/"
> <channel><title>Comments on: BASH: Prepend A Text / Lines To a File</title> <atom:link href="http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/feed/" rel="self" type="application/rss+xml" /><link>http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/</link> <description>Every answer asks a more beautiful question.</description> <lastBuildDate>Fri, 10 Feb 2012 19:55:56 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>By: Muhammad El-Sergani</title><link>http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/#comment-63508</link> <dc:creator>Muhammad El-Sergani</dc:creator> <pubDate>Fri, 14 Oct 2011 09:20:58 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1492#comment-63508</guid> <description>Thanks, works well...</description> <content:encoded><![CDATA[<p>Thanks, works well&#8230;</p> ]]></content:encoded> </item> <item><title>By: niemand</title><link>http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/#comment-62324</link> <dc:creator>niemand</dc:creator> <pubDate>Sat, 10 Sep 2011 11:50:40 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1492#comment-62324</guid> <description>A variation on this is:
echo &quot;0r header.txt
w&quot; &#124; ed myfile.txt</description> <content:encoded><![CDATA[<p>A variation on this is:</p><p>echo &#8220;0r header.txt<br
/> w&#8221; | ed myfile.txt</p> ]]></content:encoded> </item> <item><title>By: nikolocalhost</title><link>http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/#comment-61212</link> <dc:creator>nikolocalhost</dc:creator> <pubDate>Mon, 01 Aug 2011 21:28:35 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1492#comment-61212</guid> <description>That works on linux but not in solaris (unless you install gsed package), because de solaris sed command doesnt support &quot;in place option&quot; -i.
In that case
echo &quot;text&quot;&#124;cat - yourfile &gt; /tmp/out &amp;&amp; mv /tmp/out yourfile
works for me
Thanks for help :)</description> <content:encoded><![CDATA[<p>That works on linux but not in solaris (unless you install gsed package), because de solaris sed command doesnt support &#8220;in place option&#8221; -i.</p><p>In that case</p><p>echo &#8220;text&#8221;|cat &#8211; yourfile &gt; /tmp/out &amp;&amp; mv /tmp/out yourfile</p><p>works for me</p><p>Thanks for help :)</p> ]]></content:encoded> </item> <item><title>By: jbo5112</title><link>http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/#comment-61115</link> <dc:creator>jbo5112</dc:creator> <pubDate>Fri, 29 Jul 2011 00:46:41 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1492#comment-61115</guid> <description>My finally correct version (may I request a preview feature?):
&lt;pre&gt;diff -u &lt;(head myfile) &lt;(echo -e &quot;my data goes here and ends at the period.\n`head myfile`&quot;) &gt; mypatch; patch mypatch&lt;/pre&gt;</description> <content:encoded><![CDATA[<p>My finally correct version (may I request a preview feature?):</p><pre>diff -u &lt;(head myfile) &lt;(echo -e "my data goes here and ends at the period.\n`head myfile`") &gt; mypatch; patch mypatch</pre>]]></content:encoded> </item> <item><title>By: jbo5112</title><link>http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/#comment-61114</link> <dc:creator>jbo5112</dc:creator> <pubDate>Fri, 29 Jul 2011 00:44:10 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1492#comment-61114</guid> <description>&lt;pre&gt;diff -u &lt;(head -n 50 votd) &lt;(echo -e &quot;my data goes here and ends at the period.\n`head -n 50 votd`&quot;) &gt; mypatch; patch mypatch&lt;/pre&gt;</description> <content:encoded><![CDATA[<pre>diff -u &lt;(head -n 50 votd) &lt;(echo -e "my data goes here and ends at the period.\n`head -n 50 votd`") &gt; mypatch; patch mypatch</pre>]]></content:encoded> </item> <item><title>By: jbo5112</title><link>http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/#comment-61113</link> <dc:creator>jbo5112</dc:creator> <pubDate>Fri, 29 Jul 2011 00:41:10 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1492#comment-61113</guid> <description>Let&#039;s try again.
&lt;blockquote&gt;&lt;pre&gt;diff -u &lt;(head myfile)  mypatch; patch mypatch&lt;/pre&gt;&lt;/blockquote&gt;</description> <content:encoded><![CDATA[<p>Let&#8217;s try again.</p><blockquote><pre>diff -u &lt;(head myfile)  mypatch; patch mypatch</pre></blockquote> ]]></content:encoded> </item> <item><title>By: jbo5112</title><link>http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/#comment-61112</link> <dc:creator>jbo5112</dc:creator> <pubDate>Fri, 29 Jul 2011 00:39:00 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1492#comment-61112</guid> <description>Another method is using ed:
&lt;blockquote&gt;echo -e &quot;0a\nmy data goes here and ends at the period.\n.\n,wq&quot; &#124; ed myfile&lt;/blockquote&gt;</description> <content:encoded><![CDATA[<p>Another method is using ed:</p><blockquote><p>echo -e &#8220;0a\nmy data goes here and ends at the period.\n.\n,wq&#8221; | ed myfile</p></blockquote> ]]></content:encoded> </item> <item><title>By: jbo5112</title><link>http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/#comment-61111</link> <dc:creator>jbo5112</dc:creator> <pubDate>Fri, 29 Jul 2011 00:33:45 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1492#comment-61111</guid> <description>That got completely mangled.  Is there any way to protect my comments?</description> <content:encoded><![CDATA[<p>That got completely mangled.  Is there any way to protect my comments?</p> ]]></content:encoded> </item> <item><title>By: jbo5112</title><link>http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/#comment-61110</link> <dc:creator>jbo5112</dc:creator> <pubDate>Fri, 29 Jul 2011 00:32:40 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1492#comment-61110</guid> <description>You could generate a patch file and use patch.
diff -u &lt;(head myfile)  mypatch; patch mypatch</description> <content:encoded><![CDATA[<p>You could generate a patch file and use patch.</p><p>diff -u &lt;(head myfile)  mypatch; patch mypatch</p> ]]></content:encoded> </item> <item><title>By: A.Lepe</title><link>http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/#comment-61074</link> <dc:creator>A.Lepe</dc:creator> <pubDate>Thu, 28 Jul 2011 01:49:40 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1492#comment-61074</guid> <description>+1 This works very nice and without using temporally files.</description> <content:encoded><![CDATA[<p>+1 This works very nice and without using temporally files.</p> ]]></content:encoded> </item> <item><title>By: niemand</title><link>http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/#comment-60691</link> <dc:creator>niemand</dc:creator> <pubDate>Wed, 13 Jul 2011 09:51:07 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1492#comment-60691</guid> <description>Ugh, my original message totally got garbled...
What the above SHOULD look like:
From http://sed.sourceforge.net/grabbag/tutorials/sedfaq.txt:
&lt;pre&gt;
sed &#039;1{h; r file_to_prepend.txt
D; }
2{x; G; }&#039; &lt; file_to_be_prepended
&lt;/pre&gt;
This can be used to insert a file into any line but the last one into a second file. For instance, to insert file1 into file2 at line 10:
&lt;pre&gt;
sed &#039;10{h; r file1
D; }
11{x; G; }&#039; &lt;file2
&lt;/pre&gt;
&lt;em&gt;Edited by Admin - added formatting html tags&lt;em&gt;</description> <content:encoded><![CDATA[<p>Ugh, my original message totally got garbled&#8230;</p><p>What the above SHOULD look like:</p><p>From <a
href="http://sed.sourceforge.net/grabbag/tutorials/sedfaq.txt" rel="nofollow">http://sed.sourceforge.net/grabbag/tutorials/sedfaq.txt</a>:</p><pre>
sed '1{h; r file_to_prepend.txt
D; }
2{x; G; }' &lt; file_to_be_prepended
</pre><p>This can be used to insert a file into any line but the last one into a second file. For instance, to insert file1 into file2 at line 10:</p><pre>
sed &#039;10{h; r file1
D; }
11{x; G; }&#039; &lt;file2
</pre><p><em>Edited by Admin &#8211; added formatting html tags</em><em></em></p> ]]></content:encoded> </item> <item><title>By: Ladd</title><link>http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/#comment-60073</link> <dc:creator>Ladd</dc:creator> <pubDate>Fri, 17 Jun 2011 16:31:41 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1492#comment-60073</guid> <description>&#039;prepend&#039; is a corollary to &#039;append&#039;, which is an English word.</description> <content:encoded><![CDATA[<p>&#8216;prepend&#8217; is a corollary to &#8216;append&#8217;, which is an English word.</p> ]]></content:encoded> </item> <item><title>By: Ladd</title><link>http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/#comment-60072</link> <dc:creator>Ladd</dc:creator> <pubDate>Fri, 17 Jun 2011 16:28:14 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1492#comment-60072</guid> <description>This is clever; even simpler, you can use
echo &quot;prepend this&quot; &#124; cat - file.txt &gt; newfile.txt</description> <content:encoded><![CDATA[<p>This is clever; even simpler, you can use<br
/> echo &#8220;prepend this&#8221; | cat &#8211; file.txt &gt; newfile.txt</p> ]]></content:encoded> </item> <item><title>By: Mark Stafford</title><link>http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/#comment-55447</link> <dc:creator>Mark Stafford</dc:creator> <pubDate>Tue, 08 Feb 2011 19:27:08 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1492#comment-55447</guid> <description>Thanks, Q. I&#039;ve attempted something similar in the past without success.</description> <content:encoded><![CDATA[<p>Thanks, Q. I&#8217;ve attempted something similar in the past without success.</p> ]]></content:encoded> </item> <item><title>By: jbo5112</title><link>http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/#comment-55164</link> <dc:creator>jbo5112</dc:creator> <pubDate>Tue, 25 Jan 2011 17:09:55 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1492#comment-55164</guid> <description>You&#039;ll have to copy and paste the url, as the link parser cannot handle it.</description> <content:encoded><![CDATA[<p>You&#8217;ll have to copy and paste the url, as the link parser cannot handle it.</p> ]]></content:encoded> </item> <item><title>By: jbo5112</title><link>http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/#comment-55163</link> <dc:creator>jbo5112</dc:creator> <pubDate>Tue, 25 Jan 2011 17:08:40 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1492#comment-55163</guid> <description>You got gypped on your dictionary if it doesn&#039;t have prepend.
http://www.dict.org/bin/Dict?Form=Dict2&amp;Database=*&amp;Query=prepend
It&#039;s also in the Merriam-Webster Unabridged Dictionary, which is more authoritative at the cost of a subscription, and it&#039;s even a command in the popular jQuery javascript library.  However, I agree prefix would be more proper English if one cares and has an educated audience that would not be confused.</description> <content:encoded><![CDATA[<p>You got gypped on your dictionary if it doesn&#8217;t have prepend.<br
/> <a
href="http://www.dict.org/bin/Dict?Form=Dict2&#038;Database=*&#038;Query=prepend" rel="nofollow">http://www.dict.org/bin/Dict?Form=Dict2&#038;Database=*&#038;Query=prepend</a></p><p>It&#8217;s also in the Merriam-Webster Unabridged Dictionary, which is more authoritative at the cost of a subscription, and it&#8217;s even a command in the popular jQuery javascript library.  However, I agree prefix would be more proper English if one cares and has an educated audience that would not be confused.</p> ]]></content:encoded> </item> <item><title>By: Matt</title><link>http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/#comment-55079</link> <dc:creator>Matt</dc:creator> <pubDate>Fri, 21 Jan 2011 20:16:21 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1492#comment-55079</guid> <description>This perl one-liner will prefix (not prepend, which isn&#039;t a word) a line to the beginning of a file.
perl -pi -e &#039;print &quot;Put before first line\n&quot; if $. == 1&#039; inFile.txt
(from the perl FAQ):</description> <content:encoded><![CDATA[<p>This perl one-liner will prefix (not prepend, which isn&#8217;t a word) a line to the beginning of a file.</p><p>perl -pi -e &#8216;print &#8220;Put before first line\n&#8221; if $. == 1&#8242; inFile.txt</p><p>(from the perl FAQ):</p> ]]></content:encoded> </item> <item><title>By: jbo5112</title><link>http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/#comment-50061</link> <dc:creator>jbo5112</dc:creator> <pubDate>Tue, 12 Oct 2010 17:49:15 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1492#comment-50061</guid> <description>With a little creative use of shell commands, you can avoid needing a second input file.  Passing &#039;-&#039; as an argument tells most tools to use standard input or output (whichever applies) as a file.
echo &quot;my_prepend_text_goes_here&quot; &#124; tac biglist.txt - &#124; tac &gt; biglist5.txt
There are a couple of tricks where you can avoid needing to create biglist5.txt in the process (storing results to a variable or using &quot;tee&quot; to write your output), but I can&#039;t find anything that will work on large files.</description> <content:encoded><![CDATA[<p>With a little creative use of shell commands, you can avoid needing a second input file.  Passing &#8216;-&#8217; as an argument tells most tools to use standard input or output (whichever applies) as a file.</p><p>echo &#8220;my_prepend_text_goes_here&#8221; | tac biglist.txt &#8211; | tac &gt; biglist5.txt</p><p>There are a couple of tricks where you can avoid needing to create biglist5.txt in the process (storing results to a variable or using &#8220;tee&#8221; to write your output), but I can&#8217;t find anything that will work on large files.</p> ]]></content:encoded> </item> <item><title>By: jbo5112</title><link>http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/#comment-50060</link> <dc:creator>jbo5112</dc:creator> <pubDate>Tue, 12 Oct 2010 16:57:08 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1492#comment-50060</guid> <description>You need to put your prepend data into the file &quot;thisistext&quot;.  Also, unless you want your file to come out upside down, you&#039;ll have to pipe the output from the first tac into a second tac before redirecting to a file.</description> <content:encoded><![CDATA[<p>You need to put your prepend data into the file &#8220;thisistext&#8221;.  Also, unless you want your file to come out upside down, you&#8217;ll have to pipe the output from the first tac into a second tac before redirecting to a file.</p> ]]></content:encoded> </item> <item><title>By: Q</title><link>http://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/#comment-49657</link> <dc:creator>Q</dc:creator> <pubDate>Tue, 21 Sep 2010 15:22:51 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1492#comment-49657</guid> <description>This can be done with sed in place (a pretty scary operation):
sed -i -e &#039;s/^/PREFIX/&#039; file_with_lines_to_prefix.txt</description> <content:encoded><![CDATA[<p>This can be done with sed in place (a pretty scary operation):</p><p>sed -i -e &#8216;s/^/PREFIX/&#8217; file_with_lines_to_prefix.txt</p> ]]></content:encoded> </item> </channel> </rss>
