Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
We don't bite newbies here... much
 
PerlMonks  

redirect grep output

by Anonymous Monk
on Jan 12, 2001 at 17:23 UTC ( [id://51421]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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

Below is a snippet of a simple script giving me problems. The first use of fgrep marked (1) redirects GREAT. The last 4 marked (2) simply output to the screen and ignore my pipe! If I change the $log to a constant it works fine? Any ideas?

#Scan the log dir for useful logfiles
chdir ("$BackPath");
(1) system "fgrep -l $Date * > /nwscan/tmplog";
chdir ("$MainPath");
$log1 = $target[0];
$log2 = $target1;
$log3 = $target2;
#print $log1;
#print $log2;
#print $log3;
chdir ("$BackPath");
(2)system "fgrep server $log1>>/nwscan/$Server";
(2)system "fgrep type $log1>>/nwscan/$Server";
(2)system "fgrep started $log1>>/nwscan/$Server";
(2)system "fgrep completion $log1>>/nwscan/$Server";

Replies are listed 'Best First'.
Re: redirect grep output
by adamsj (Hermit) on Jan 12, 2001 at 17:26 UTC
    Have you considered defining $Server?

    Also, what is system returning when you make those calls? Have you checked that yet?

Re: redirect grep output
by Adam (Vicar) on Jan 12, 2001 at 17:40 UTC
    Any ideas?
    Yes.
    1. use strict;
    2. use warnings; or -w on Perl < 5.6
    3. check the sucess of system calls.
    4. use strict;
    5. use whitespace in your system calls.
    6. use <code> tags when posting code here
    7. use strict;
Re: redirect grep output
by chipmunk (Parson) on Jan 12, 2001 at 17:40 UTC
    You don't show where the value that ends up in $log1 comes from originally, but I'll bet you need to chomp it to remove a newline. If $log1 ends in a newline, then you're really passing two separate commands to system, an fgrep and a redirection of nothing.
      Thanks alot! A stupid mistake, but I am by no means a "Perl Monk". I chomped the var and it worked great!
      Kenny

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://51421]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.