Monday, February 17, 2014

executing grep command

www.unixbabuforum.inI have written following script 
error_found=/bin/grep -P -i -e [\s]+error[s]*[:]* |^[\s]error [1-9] $logfile > /tmp/builderror.txt 
echo $error_found 
when i execute i get error saying ./ line 3: ^[s]error: command not found 
./ line 3: -P: command not found 

But if i execute command on command line /bin/grep -P -i -e [\s]+error[s]*[:]* |^[\s]error [1-9] $logfile > /tmp/builderror.txt it works. 
How to resolve this problem

www.unixbabuforum.inYou're attempting to assign the output of the grep command to a variable. 

If you want to echo the variable and also write output to file, try the following: 

error_found=`/bin/grep -P -i -e [\s]+error[s]*[:]* |^[\s]error [1-9] $logfile` # Notice tics surrounding command 
echo $error_found 
/bin/grep -P -i -e [\s]+error[s]*[:]* |^[\s]error [1-9] $logfile >/tmp/file # this writes out to file


Post a Comment

Design by BABU | Dedicated to grandfather | welcome to BABU-UNIX-FORUM