Home » Infrastructure » Unix » shell script using grep and piping
shell script using grep and piping [message #97399] Thu, 18 April 2002 06:25 Go to next message
Messages: 182
Registered: April 1998
Senior Member
Hi Guys, i'm trying to get the following grep command working in my shell script but am unable to because it throws errors when i put a variable in the command line of grep. Any ideas would be much appreciated.

i basically want to concatenate two commands, grep and wc, but do it using a variable as seen below.

==================script contents===============
wcount='| wc -l'

grep -i "#include" myHeader.h $wcount


the above script throws errors because i think it's seeing it as:-

grep -i "#include" myHeader.h "&#124" "wc" "-l"
Re: shell script using grep and piping [message #97400 is a reply to message #97399] Thu, 18 April 2002 11:19 Go to previous message
Messages: 88
Registered: November 1999
Don't include the | char in your wcount variable.

what you have: (problem)
$ cat b.sh
wordcnt="&#124wc -l"

mycount=`grep -i "#include" myhead.h $wordcnt`

echo $mycount
$ b.sh
grep: can't open &#124wc
grep: can't open -l
myhead.h:#include myhead.h:#include


Should be: (solution)
$ more myhead.h
$ cat b.sh
wordcnt="wc -l"

mycount=`grep -i "#include" myhead.h &#124$wordcnt`

echo $mycount
$ b.sh
Previous Topic: Re: Oracle applications on NT and UNIX
Next Topic: oracle for saloris 8i
Goto Forum:

Current Time: Fri Jun 09 23:51:03 CDT 2023