in reply to Re: Opening multiple files in directory
in thread Opening multiple files in directory
Just wanted to say thanks this helped me a lot making this:
grepcertainfilesgrepcertainlinesandputresultsinfiles.pl
#!/usr/bin/perl use strict; use warnings; # FIND THE PATH TO THE Directory: my $dir = $ARGV[0]; opendir(DIR, $dir) or die $!; # select for files with names containing txt.fit my @files= grep { /txt.fit/ } readdir DIR; closedir DIR; # Read files line by line foreach my $file(@files) { open IN, "<$file" or die $!; my $tree = (); while(<IN>) { # skip everything in file not conatining Tree mixture next unless ($_ =~ m/Tree mixture/); # remove content from line thats unwanted in output $tree = $_; $tree =~s/Tree mixtureTree=//; } #name output file after input file but add .tre my $outfile = "$file.tre"; # here i 'open' the file, saying i want to write to it with the '>>' s +ymbol open (FILE, ">> $outfile") || die "problem opening $outfile\n"; print FILE $tree; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Opening multiple files in directory
by Athanasius (Archbishop) on Aug 31, 2014 at 16:50 UTC |