Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks, who are always smarter than me. I'm trying to use the following code but rather than modify just one file to contain only unique lines I'm trying to modify many files in a directory.
I've successfully erased my data 5 times with some not so successful modifications so far so I'm seeking some wisdom. Here's the first bit of code:
#!/usr/bin/perl –w open(INF,"db.txt"); @data = <INF>; close(INF); @sd = sort(@data); for(@sd){ push @out, $_ if (not @out) or ($out[-1] ne $_); }; open(OUTF,">outdb.txt"); print OUTF; close(OUTF);
I'm pretty sure I'm overthinking it and the solution is very, very simple. Here's my code to find the files. See below. I just can't seem to get the two bits of code together properly.
#find the files I want to change my @files; find( sub { return unless -f; # Files only return unless /\.txt$/; # Name must end in ".txt" push @files, $File::Find::name; }, $directory );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: parse multiple text files keep unique lines only
by 1nickt (Canon) on Jun 27, 2017 at 20:25 UTC | |
|
Re: parse multiple text files keep unique lines only
by thanos1983 (Parson) on Jun 28, 2017 at 00:01 UTC | |
|
Re: parse multiple text files keep unique lines only
by tybalt89 (Monsignor) on Jun 28, 2017 at 02:01 UTC | |
by 1nickt (Canon) on Jun 28, 2017 at 08:02 UTC | |
by tybalt89 (Monsignor) on Jun 28, 2017 at 13:05 UTC | |
by tybalt89 (Monsignor) on Jul 01, 2017 at 02:53 UTC | |
|
Re: parse multiple text files keep unique lines only
by Anonymous Monk on Jun 28, 2017 at 04:45 UTC |