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.
In reply to Grep file out of directory and read into array by Jalcock501
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |