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.
$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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oh, in your case command inside 'open' should like as "ssh $host grep 'string1\|string2' $log_file" of course
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.