siddheshsawant has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: Doubt regarding find and grep command
by hexcoder (Curate) on Jun 18, 2010 at 19:17 UTC
    I am not able to determine what exactly your problem is. From your first sentence I read: you have a given file name and want to find that file at a specific location (which I assume is a directory). If you just want that, you can use Perl's file test operator and avoid external calls to find and grep completely (see file test ops).

    Like this

    use strict; use warnings; if (-f '/pptai/nightly_db/data_loader_logs/2010-06-18_AIX_nightly_data +_loader.log') { # file exists ... } else { # file does not exist as a plain file }
    If you want to check if the given file name is listed in a line of some other text file, you can use a simple loop for that. The file is read line by line until the file name is found or the text file has been read completely.
    use strict; use warnings; my $searchstring = '/pptai/nightly_db/data_loader_logs'; open my $rfh, '<', '2010-06-18_AIX_nightly_data_loader.log' or die "ca +nnot open file:$!\n"; while (defined($_ = <$rfh>)) { if (0 <= index $_, $searchstring) { # file name is part of the current line print ; last; } } close $rfh or die "cannot close:$!\n";
Re: Doubt regarding find and grep command
by toolic (Bishop) on Jun 18, 2010 at 18:47 UTC
    If you are trying to use the grep and find Unix utilities, reading the manpages should clear things up for you.
Re: Doubt regarding find and grep command
by Marshall (Canon) on Jun 20, 2010 at 06:35 UTC
    Sounds like you have a specified place for the nightly logs. To get a listing of the ".log" files, adapt this code which lists the ".pl" files in my C:/temp directory...

    #!/usr/bin/perl -w use strict; my $path = "C:/temp"; opendir (my $dirhandle, $path) || die "cannot open dir $path"; my @perl_files = grep {/.pl$/} readdir $dirhandle; print "@perl_files";
    A directory is opened, then all files in that directory are read and filtered by grep{}. Note that a directory within that directory is just a special kind of "file", but filtering on things that end in ".log" probably eliminates them, but be aware that it might not, that case you need a file test, like "-f".

    In your case, I would think that: $path="/pptai/nightly_db/data_loader_logs"; along with "grep{/.log$/}" would yield all log files. Note that if you want to do a "file test" like -e, -f, etc, you will need to test the complete file path name, "$path/$specific_file". Above @perl_files only contains the file names, not the full paths. Oh, also enclose "$path/$specific_file" in quotes otherwise Perl will think that you are doing division!