Link to home
Start Free TrialLog in
Avatar of urivera
urivera

asked on

How to use grep for multiple strings in perl

Using perl I need to ssh to a remote host and grep a file for strings.  For example, if I want to search just 'string1'  I would do the line of code below and it works.

$my result = qx{ssh $host grep string1 $log_file};

however I want to search 2 or 3 strings in the file. I tried
$my result = qx{ssh $host grep 'string1\|string2' $log_file};

but that does not work.  
The grep command is right because if execute from the shell prompt I get the lines containing either string1 or string2.
SOLUTION
Avatar of ht-docs
ht-docs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ht-docs
ht-docs

Oh, in your case command inside 'open' should like as "ssh $host grep 'string1\|string2' $log_file" of course
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial