Jalcock501 has asked for the wisdom of the Perl Monks concerning the following question:
This is probably really simple but I cannot for the life of me find any material on this.
I need to write a script that allows someone to enter a reference code when prompted, I already have this but.... I need the script to search a directory full of other directories for a file containing that string which I assume I can use grep for, the difficult bit, for me, is I want to grep the file and then read it into an array like thispseudo code: #!/usr/bin/perl -w use strict; use warn; my $REF; my @LINES; my $DPT_DIR=/shares/test/PPdir/ print "ENTER REF NUMBER"; chomp($REF = <>); grep "$REF" */*.dpt open my $FH, '<', *.dpt file grep has found chomp(@LINES, $FH); close $FH
Any help would be greatly appreciated.
ThanksJim
EDIT: Apologies it has be come apparent to me this isn't very clear, I don't need the list of files in an array but the contents of a single file.there are going to be several *.dpt all containing different refs which is why I need to do a grep/findLinux grep: #grep -l ABC123 */*.dpt lloydf/test.dpt <-- I need to read this file.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Grep file out of directory and read into array
by pme (Monsignor) on Dec 08, 2014 at 13:59 UTC | |
by Jalcock501 (Sexton) on Dec 08, 2014 at 15:18 UTC | |
by pme (Monsignor) on Dec 08, 2014 at 15:37 UTC | |
by Jalcock501 (Sexton) on Dec 08, 2014 at 15:50 UTC | |
by Jalcock501 (Sexton) on Dec 08, 2014 at 16:36 UTC | |
by Jalcock501 (Sexton) on Dec 08, 2014 at 14:01 UTC | |
|
Re: Grep file out of directory and read into array
by marto (Cardinal) on Dec 08, 2014 at 14:03 UTC | |
|
Re: Grep file out of directory and read into array
by RichardK (Parson) on Dec 08, 2014 at 15:44 UTC | |
by Anonymous Monk on Dec 08, 2014 at 19:04 UTC |