panthema / 2012 / 1119-eSAIS-Inducing-Suffix-and-LCP-Arrays-in-External-Memory / eSAIS-DC3-LCP-0.5.0 / stxxl / misc / concat-lines (Download File)
#!/usr/bin/perl

############################################################################
#  misc/concat-lines
#
#  Part of the STXXL. See http://stxxl.sourceforge.net
#
#  Copyright (C) 2007 Johannes Singler <singler@ira.uka.de>
#  Copyright (C) 2010 Andreas Beckmann <beckmann@cs.uni-frankfurt.de>
#
#  Distributed under the Boost Software License, Version 1.0.
#  (See accompanying file LICENSE_1_0.txt or copy at
#  http://www.boost.org/LICENSE_1_0.txt)
############################################################################

# Concatenate the lines of file $ARGV[0] which both satisfy regular expression $ARGV[1]

$regex = $ARGV[0];
shift;
$former = '';
while($line = <>)
{
  if(!($line =~ /$regex/) || !($former =~ /$regex/))
  {
    print("\n");
  }
  else
  {
    print("\t");
  }
  chomp($line);
  print($line);
  $former = $line;
}
print("\n");