title: How can I grep and sort text files using Perl?
body: <p>I have a simple log file which is very messy and I need it to be neat. The file contains log headers, but they are all jumbled up together. Therefore I need to sort the log files according to the log headers. There are no static number of lines - that means that there is no fixed number of lines for the each header of the text file. And I am using perl grep to sort out the headers.</p>
  
  <p>The Log files goes something like this:</p>
  
  <pre><code>Car LogFile Header
  &lt;text&gt;
  &lt;text&gt;
  &lt;text&gt;
  Car LogFile Header
  &lt;text&gt;
  Car LogFile Header
  &lt;and so forth&gt;
  </code></pre>
  
  <p>I have done up/searched a simple algorithm but it does not seem to be working. Can someone please guide me? Thanks!</p>
  
  <pre><code>#!/usr/bin/perl
  
  #use 5.010; # must be present to import the new 5.10 functions, notice 
  #that it is 5.010 not 5.10
  
  
  my $srce = "./root/Desktop/logs/Default.log";
  my $string1 = "Car LogFile Header";
  open(FH, $srce);
  my @buf = &lt;FH&gt;;
  close(FH);
  my @lines = grep (/$string1/, @buffer);
  </code></pre>
  
  <p>After executing the code, there is no result shown at the terminal. Any ideas?</p>