#!/usr/bin/perl # The Missing Textutils, Ondrej Bojar, obo@cuni.cz # http://www.cuni.cz/~obo/textutils # # 'lcat' is like 'cat' but the concatenated files are prefixed with the # filename. The name stands for 'labelled cat'. # # $Id: lcat,v 1.5 2009-05-28 23:15:49 bojar Exp $ # use strict; use Getopt::Long; my $head = 0; # use 'head'-like format ==> FN <== my $delim = "\t"; my @glob = (); my $fl = undef; GetOptions( "head"=>\$head, "delim"=>\$delim, "glob=s" => \@glob, "fl=s" => \$fl, ); my @fl = (); if (defined $fl) { if ($fl eq "-") { *IN = *STDIN; } else { open IN, $fl or die "Can't read $fl"; } while () { chomp; push @fl, $_; } if ($fl ne "-") { close(IN); } } foreach my $fn (@ARGV, (map {(glob($_));} @glob), @fl) { if ($fn eq "-") { while (<>) { print "$delim$_"; } } else { my $ofn = $fn; $ofn = "zcat $fn |" if $fn =~ /\.gz$/; $ofn = "bzcat $fn |" if $fn =~ /\.bz2$/; print "==> $fn <==\n" if $head; open INF, $ofn or die "Can't open '$ofn'"; while () { if ($head) { print; } else { print "$fn$delim$_"; } } close INF; } }