<?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>Learning by Doing &#187; cygwin</title>
	<atom:link href="http://tech.williamgunn.org/tag/cygwin/feed/" rel="self" type="application/rss+xml" />
	<link>http://tech.williamgunn.org</link>
	<description>...and trying, and failing, and trying again.</description>
	<lastBuildDate>Wed, 25 Mar 2009 00:17:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>How to remove the last n lines from a directory full of csv files.</title>
		<link>http://tech.williamgunn.org/2009/03/24/how-to-remove-the-last-n-lines-from-a-directory-full-of-csv-files/</link>
		<comments>http://tech.williamgunn.org/2009/03/24/how-to-remove-the-last-n-lines-from-a-directory-full-of-csv-files/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 00:17:47 +0000</pubDate>
		<dc:creator>Mr. Gunn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cygwin]]></category>
		<category><![CDATA[head]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[truncate csv]]></category>

		<guid isPermaLink="false">http://tech.williamgunn.org/2009/03/24/how-to-remove-the-last-n-lines-from-a-directory-full-of-csv-files/</guid>
		<description><![CDATA[First, install Cygwin. Next, add the cygwin\bin directory to your path (control panel\system ->advanced settings -> environment variables Create a script to invoke the head command and iterate over the files and put the script in the \cygwin\bin directory. Call it truncate.sh. Add the shebang to the file (#!c:/cygwin/bin/bash) at the top Make it executable [...]]]></description>
			<content:encoded><![CDATA[<p>First, install Cygwin.<br />
Next, add the cygwin\bin directory to your path (control panel\system ->advanced settings -> environment variables<br />
Create a <a href="git://gist.github.com/65881.git">script to invoke the head command and iterate over the files</a> and put the script in the \cygwin\bin directory.<br />
Call it truncate.sh.<br />
Add the shebang to the file (#!c:/cygwin/bin/bash) at the top<br />
Make it executable by running chmod a+x c:\cygwin\bin\truncate.sh (might not be necessary?)<br />
Open a command window in the directory containing your files to be truncated.<br />
Set the starting and ending variables to the right numbers.<br />
Set the number after -n to the last row you want in your data files.<br />
Save truncate.sh<br />
Run dos2unix c:\cygwin\bin\truncate.sh<br />
Type bash c:\cygwin\bin\truncate.sh<br />
Your files will now be truncated and named. [filename].bak You can use a file renaming utility such as <a href="http://cerebralsynergy.com/download.php?view.55">Batch File Renamer</a> to rename all the files to .csv</p>
<p>Improvements that could be made:<br />
Counting the number of files and determining the right starting and ending filename.<br />
Taking user input for the row to truncate after.<br />
Writing the files as the right extension, but in a \truncated directory.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.williamgunn.org/2009/03/24/how-to-remove-the-last-n-lines-from-a-directory-full-of-csv-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

