Hi,
I have written the following shell script -
Error_String="error"
var1="| grep -v note1 | grep -v note2"
grep -i $Error_String /users/mqm/Pwork/Err/*.out $var1
The above script gives error saying "grep: can't open |
grep: can't open grep
grep: can't open -v" etc
In my program note1 and note2 strings are dynamically generated, so I cannot hardcode those in grep command.
Could anyone please help me to resolve this problem
Thanks in advance,
Prasanna
Problem - Grep cammand in shell script
Started by prasannasupp, Sep 02 2009 02:55 AM
2 replies to this topic
#1
Posted 02 September 2009 - 02:55 AM
|
|
|
#2
Posted 04 September 2009 - 07:45 AM
First of all, say excatily you are trying to acomplish.
var1 is supposed to contain the string "| grep -v note1 | grep -v note2" or the result of grep command?
var1 is supposed to contain the string "| grep -v note1 | grep -v note2" or the result of grep command?
#3
Posted 08 September 2009 - 08:36 AM
You need to change note1 and note2 to $note1 and $note2. I would do it like this:
The reason why $var1 didn't work was because the shell automatically quoted it when it expanded the variable. So the command line actually looked like this:
grep -i $Error_String /users/mqm/Pwork/Err/*.out "| grep -v note1 | grep -v note2"
In addition to grepping every .out file, grep would have also tried to open a file called | grep -v note1 | grep -v note2, which of course doesn't exist.
result=$(grep -i $Error_String /users/mqm/Pwork/Err/*.out | grep -v $note1 | grep -v $note2)
The reason why $var1 didn't work was because the shell automatically quoted it when it expanded the variable. So the command line actually looked like this:
grep -i $Error_String /users/mqm/Pwork/Err/*.out "| grep -v note1 | grep -v note2"
In addition to grepping every .out file, grep would have also tried to open a file called | grep -v note1 | grep -v note2, which of course doesn't exist.
sudo rm -rf /


Sign In
Create Account

Back to top









