[go: up one dir, main page]

Menu

[b40542]: / misc / concat-lines  Maximize  Restore  History

Download this file

35 lines (31 with data), 815 Bytes

#!/usr/bin/perl

############################################################################
#  misc/concat-lines
#
#  Part of the STXXL. See http://stxxl.sourceforge.net
#
#  Copyright (C) 2007 Johannes Singler <singler@ira.uka.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]

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