shell script using grep and piping [message #97399] |
Thu, 18 April 2002 06:25 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
JOHN
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 "|" "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 Go to previous message](/forum/theme/orafaq/images/up.png) |
Cindy
Messages: 88 Registered: November 1999
|
Member |
|
|
Don't include the | char in your wcount variable.
what you have: (problem)
==================================================
$ cat b.sh
wordcnt="|wc -l"
mycount=`grep -i "#include" myhead.h $wordcnt`
echo $mycount
$ b.sh
grep: can't open |wc
grep: can't open -l
myhead.h:#include myhead.h:#include
$
========================================================
Should be: (solution)
=====================================================
$ more myhead.h
#include
#include
$ cat b.sh
wordcnt="wc -l"
mycount=`grep -i "#include" myhead.h |$wordcnt`
echo $mycount
$ b.sh
2
$
|
|
|