<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How Can I Delete Just the Last Line of a Text File?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2006/09/11/how-can-i-delete-just-the-last-line-of-a-text-file.aspx</link><description>Hey, Scripting Guy! How can I delete just the last line of a text file? -- AD 
 Hey, AD. You know, it’s been a long, hard day here at Microsoft, one of those days when everyone and everything seems to be against you. Many people, when faced with a day</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: How Can I Delete Just the Last Line of a Text File?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2006/09/11/how-can-i-delete-just-the-last-line-of-a-text-file.aspx#3459781</link><pubDate>Mon, 17 Oct 2011 20:35:06 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3459781</guid><dc:creator>jv</dc:creator><description>&lt;p&gt;@Ed - I think the method I used here will always prevent that with VBScript. &amp;nbsp;LOading teh file into an array seems to always retain teh blank line. &amp;nbsp;When we write out all of the lines into the new file and close it without adding teh blank line the FSO just adds a new blank line.&lt;/p&gt;
&lt;p&gt;I believe that this is because the EOF marker is always acting like a new line. &amp;nbsp;If I backspace, remove the blank line then reopen the file, the blank line will always have returned. &amp;nbsp;If I load a file into an array in PowerSHell the pseudo-blank line will never be loaded.&lt;/p&gt;
&lt;p&gt;This has always been a headache in VBScript but almost nowhere else.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3459781" width="1" height="1"&gt;</description></item><item><title>re: How Can I Delete Just the Last Line of a Text File?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2006/09/11/how-can-i-delete-just-the-last-line-of-a-text-file.aspx#3459778</link><pubDate>Mon, 17 Oct 2011 20:12:57 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3459778</guid><dc:creator>Ed Wilson</dc:creator><description>&lt;p&gt;@JV You have hit upon a key problem in working with text files ... when there is a blank line at the end of the file, lots of things break. This is also an issue with many CSV type of files, and iterating through a collection ... often the last (blank line) will generate an error. The only way to ensure no blank line, is to go to the end of the text file, and backspace until your cursor appears at the end of the last line. I actually talk about this problem in the following Hey Scripting Guy blog article: &lt;a rel="nofollow" target="_new" href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/09/19/avoid-blank-lines-at-end-of-a-text-file-with-powershell.aspx"&gt;blogs.technet.com/.../avoid-blank-lines-at-end-of-a-text-file-with-powershell.aspx&lt;/a&gt; &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3459778" width="1" height="1"&gt;</description></item><item><title>re: How Can I Delete Just the Last Line of a Text File?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2006/09/11/how-can-i-delete-just-the-last-line-of-a-text-file.aspx#3459776</link><pubDate>Mon, 17 Oct 2011 20:04:31 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3459776</guid><dc:creator>jv</dc:creator><description>&lt;p&gt;No problem with last line being retained in this exact script but there is that old issue of disagreement over what constitutes the last line in a text file.&lt;/p&gt;
&lt;p&gt;If the original file ends with a blank line then the last line will not be removed. &amp;nbsp;The new file will also be created with the last line being blank. &amp;nbsp;The sum total is that the file will not be any different. &amp;nbsp;Remove the blank line and all will work well.&lt;/p&gt;
&lt;p&gt;Here is the ‘look-ahead’ method for removing the last line that will not see the blank line as a line.&lt;/p&gt;
&lt;p&gt;##############################################&lt;/p&gt;
&lt;p&gt;Set fso = CreateObject(&amp;quot;Scripting.FileSystemObject&amp;quot;)&lt;/p&gt;
&lt;p&gt;Set infile = fso.OpenTextFile(&amp;quot;ltest.txt&amp;quot;)&lt;/p&gt;
&lt;p&gt;Set outfile = fso.OpenTextFile(&amp;quot;ltest3.txt&amp;quot;, 2,true) &amp;#39;ForWriting, Create&lt;/p&gt;
&lt;p&gt;Do&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;line = infile.ReadLine()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;if infile.AtEndOfStream Then Exit Do&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;outfile.WriteLine line&lt;/p&gt;
&lt;p&gt;Loop While True&lt;/p&gt;
&lt;p&gt;infile.close&lt;/p&gt;
&lt;p&gt;outfile.Close&lt;/p&gt;
&lt;p&gt;##############################################&lt;/p&gt;
&lt;p&gt;This is an interesting ‘race’ condition with the FSO that, as far as I know, &amp;nbsp;does not seem to arise in other implementations of the file API.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3459776" width="1" height="1"&gt;</description></item><item><title>re: How Can I Delete Just the Last Line of a Text File?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2006/09/11/how-can-i-delete-just-the-last-line-of-a-text-file.aspx#3459761</link><pubDate>Mon, 17 Oct 2011 18:22:28 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3459761</guid><dc:creator>Ed Wilson</dc:creator><description>&lt;p&gt;@Anthony thanks, I am glad you like the script. &lt;/p&gt;
&lt;p&gt;@Rob thanks for the update. &lt;/p&gt;
&lt;p&gt;@Grace, it is REALLY hard to troubleshoot a script sight unseen :-) I would suggest you post both your script, and your text file to the Official Scripting Guys Forum where there are many experts who would be glad to help you. The link is here: &lt;a rel="nofollow" target="_new" href="http://social.technet.microsoft.com/Forums/en/ITCG/threads/"&gt;social.technet.microsoft.com/.../threads&lt;/a&gt; &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3459761" width="1" height="1"&gt;</description></item><item><title>re: How Can I Delete Just the Last Line of a Text File?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2006/09/11/how-can-i-delete-just-the-last-line-of-a-text-file.aspx#3459735</link><pubDate>Mon, 17 Oct 2011 17:25:46 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3459735</guid><dc:creator>Grace</dc:creator><description>&lt;p&gt;I have a two line text file. I implemented this script and the last line is printed instead of the first line. &amp;nbsp;Any ideas?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3459735" width="1" height="1"&gt;</description></item><item><title>re: How Can I Delete Just the Last Line of a Text File?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2006/09/11/how-can-i-delete-just-the-last-line-of-a-text-file.aspx#3441216</link><pubDate>Wed, 13 Jul 2011 00:39:46 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3441216</guid><dc:creator>Rob</dc:creator><description>&lt;p&gt;The link to the previous column in the second last paragraph is &amp;nbsp;busted. &amp;nbsp;Contents are http://null/technet/scriptcenter/resources/qanda/may05/hey0520.mspx&lt;/p&gt;
&lt;p&gt;It should be &lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://blogs.technet.com/b/heyscriptingguy/archive/2005/05/20/how-can-i-remove-the-last-carriage-return-linefeed-in-a-text-file.aspx"&gt;blogs.technet.com/.../how-can-i-remove-the-last-carriage-return-linefeed-in-a-text-file.aspx&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3441216" width="1" height="1"&gt;</description></item><item><title>re: How Can I Delete Just the Last Line of a Text File?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2006/09/11/how-can-i-delete-just-the-last-line-of-a-text-file.aspx#3370513</link><pubDate>Mon, 22 Nov 2010 22:51:02 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3370513</guid><dc:creator>Anthony</dc:creator><description>&lt;p&gt;Lots of credit and many thanks for the script but the meatloaf recipe, hmmm I dont know, I&amp;#39;ll pass.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3370513" width="1" height="1"&gt;</description></item></channel></rss>