Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Extract information from several files in directory

by tybalt89 (Prior)
on Nov 27, 2020 at 16:06 UTC ( #11124292=note: print w/replies, xml ) Need Help??


in reply to Extract information from several files in directory

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11124292]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2021-01-21 23:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?