In before everyone else suggests using a module for this.
Path::Tiny is my current favorite module for general file bashing.
#!/usr/bin/perl
use strict; # https://perlmonks.org/?node_id=11124289
use warnings;
use Path::Tiny;
my $dirname = 'Filer';
my $outputfile = path('output.second.column');
$outputfile->spew(''); # empty file
for my $file ( path($dirname)->children( qr/\.txt\z/ ) )
{
$outputfile->append( map { (split /\t|\n/)[1] . "\n"} $file->lines )
+;
}
# following for debug only :)
system 'more Filer/* output.second.column | cat';
# because 'more' shows filename and contents when piped
Outputs:
::::::::::::::
Filer/one.txt
::::::::::::::
one two three
four five six
::::::::::::::
Filer/three.txt
::::::::::::::
thirteen fourteen fifteen
sixteen seventeen eighteen
::::::::::::::
Filer/two.txt
::::::::::::::
even eight nine
ten eleven twelve
::::::::::::::
output.second.column
::::::::::::::
two
five
fourteen
seventeen
eight
eleven
Is this the kind of thing you were looking for ?
P.S. See, it really is simple...
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|