<?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>Code Library &#187; File</title>
	<atom:link href="http://www.ucosoft.com/tag/file/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ucosoft.com</link>
	<description>Free Source Code and Program Tips</description>
	<lastBuildDate>Thu, 22 Jul 2010 05:17:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to hook the file related event</title>
		<link>http://www.ucosoft.com/how-to-hook-the-file-related-event.html</link>
		<comments>http://www.ucosoft.com/how-to-hook-the-file-related-event.html#comments</comments>
		<pubDate>Fri, 22 Jun 2007 03:29:35 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[File]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[How-to]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2007/06/22/how-to-hook-the-file-related-event.html</guid>
		<description><![CDATA[How to hook the file related event? It depends on what you need to do when such an event takes places. If what you just want to be notified, FindFirstChangeNotification and ReadDirectoryChanges are enough. If you need to intercept adn affect the operation somehow, I have heard it can be done with a kenerl-level driver(Filesystem [...]]]></description>
			<content:encoded><![CDATA[<p>How to hook the file related event?</p>
<p>It depends on what you need to do when such an event takes places. If what you just want to be notified, <B>FindFirstChangeNotification</B> and <B>ReadDirectoryChanges</B> are enough.</p>
<p>If you need to intercept adn affect the operation somehow, I have heard it can be done with a kenerl-level driver(Filesystem Driver), but I have no experience about it.</p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/api" title="API" rel="tag">API</a>, <a href="http://www.ucosoft.com/tag/file" title="File" rel="tag">File</a>, <a href="http://www.ucosoft.com/tag/hook" title="hook" rel="tag">hook</a>, <a href="http://www.ucosoft.com/tag/how-to" title="How-to" rel="tag">How-to</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/how-to-hook-the-file-related-event.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>File processing &#8212; Remove the first column of each line</title>
		<link>http://www.ucosoft.com/file-processing-remove-the-first-column-of-each-line.html</link>
		<comments>http://www.ucosoft.com/file-processing-remove-the-first-column-of-each-line.html#comments</comments>
		<pubDate>Fri, 24 Nov 2006 08:27:51 +0000</pubDate>
		<dc:creator>hamo</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[File]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[Script]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/archives/33.html</guid>
		<description><![CDATA[Question I have a text file with a lot of lines, and in each line, there are several columns divided by space character, but the number of columns in each line varies. For example, here is a sample &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; abc 123 234 456 bsc 3 5 7 9 10 123 yyt 23 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; I want [...]]]></description>
			<content:encoded><![CDATA[<h3> Question</h3>
<p><P><br />
I have a text file with a lot of lines, and in each line, there are several columns divided by space character, but the number of columns in each line varies. For example, here is a sample</P></p>
<p><Pre>
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;
abc 123 234 456
bsc 3 5 7 9 10 123
yyt 23
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;
</pre></p>
<p>
I want to get a new file based on the existing file, by removing the first column, here is the related output of above sample,
</p>
<pre>
--------------------
123 234 456
3 5 7 9 10 123
23
--------------------
</pre>
<p><!--adsense--></p>
<h3>Solution</h3>
<p> perl is a bit faster than cut:<br />
<coolcode lang="perl" linenum="no"><br />
perl -pe &#8216;s/^[^ ]+\ *//&#8217;<br />
</coolcode></p>
<p>Sed is a slower:<br />
<coolcode lang="perl" linenum="no"><br />
sed -e &#8216;s/^[^ ]\+\ *//&#8217;<br />
</coolcode></p>
<p>Note: If you accept leading space characters, cut won&#8217;t work properly (it would treat the first field as being empty), but perl can work:</p>
<p><coolcode lang="perl" linenum="no"><br />
perl -pe &#8216;s/^\ *[^ ]+\ *//&#8217;<br />
</coolcode></p>
<p>a little more robust program.<br />
<span id="more-33"></span></p>
<p><coolcode lang="cpp" linenum="no"><br />
#include <iostream><br />
#include <string></p>
<p>int main(int argc, char* argv[])<br />
{<br />
 using std::string;</p>
<p> while (1)<br />
 {<br />
  string str_one_line;<br />
  if (!getline(std::cin, str_one_line))<br />
   break;</p>
<p>  string::size_type pos = str_one_line.find_first_of(&#8216; &#8216;);<br />
  if (pos == string::npos)<br />
  {<br />
   std::cerr << "There is no space char in the string." << std::endl;<br />
   return 1;<br />
  }</p>
<p>  pos = str_one_line.find_first_not_of(' ', pos + 1);<br />
  if (pos == string::npos)<br />
  {<br />
   std::cerr << "There is no char after space char." << std::endl;<br />
   return 1;<br />
  }</p>
<p>  std::cout << str_one_line.substr(pos) << std::endl;<br />
 }<br />
 return 0;<br />
}<br />
</coolcode></p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/file" title="File" rel="tag">File</a>, <a href="http://www.ucosoft.com/tag/how-to" title="How-to" rel="tag">How-to</a>, <a href="http://www.ucosoft.com/tag/script" title="Script" rel="tag">Script</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/file-processing-remove-the-first-column-of-each-line.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

