Monday, February 17, 2014

executing grep command

www.unixbabuforum.inI have written following script 
#!/bin/bash 
logfile=~/build.log 
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 ./grep.sh: line 3: ^[s]error: command not found 
./grep.sh: 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

0 comments:

Post a Comment

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