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...


In reply to Re: Extract information from several files in directory by tybalt89
in thread Extract information from several files in directory by Sofie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.