Trouble getting the right output from a file
<p>Okay so here is my code:<a href="http://pastebin.com/ajc3cXEc" rel="nofollow">Pastebin</a></p>

<p>What i want to do is read from the file /etc/passwd and extract all the users with an UID over 1000 but less than 65000. With those users i also want to print out how many times they have logged in. And with this current code the output is like this:</p>

<blockquote>
  <p>user:15</p>
  
  <p>User:4</p>
  
  <p>User:4</p>
</blockquote>

<p>The problem with this is that they haven't logged in 15 times or 4 times, because the program is counting every line that is output from the "last" command. So if i run the command "last -l user" it will look something like this:</p>

<pre><code>user     pts/0        :0               Mon Feb 15 19:49 - 19:49  (00:00)
user     :0           :0               Mon Feb 15 19:49 - 19:49  (00:00)

wtmp begins Tue Jan 26 13:52:13 2016
</code></pre>

<p>The part that i'm interested in is the "user       :0" line, not the others. And that is why the program outputs the number 4 instead of 1, like it should be. So i came up with a regular expression to only get the part that i need and it looks like this:</p>

<pre><code>\n(\w{1,9})\s+:0
</code></pre>

<p>However i cannot get it to work, i only get errors all of the time.
Im hoping someone here might be able to help me.</p>