test wordcount

Hello

I want to run this test:

If wordcount of a command is 0 then echo XXXX else echo YYYYY

if [ `cat /tmp/foobar.txt | awk '{print $2}' | grep database | grep -v `df -k |grep /dev/dsk | awk '{print $6}'` | wc -l` != 0 ]; then echo "all devices are created on RAID10"; else echo "Some devices are created on non-RAID10"; fi

I receive this message
-bash: command substitution: line 1: syntax error near unexpected token `|'
-bash: command substitution: line 1: ` | wc -l'
Usage: grep -hblcnsviw pattern file . . .
awk: can't open !=
-bash: [: missing `]'
Some devices are created on non-RAID10

Can you please advise?

bash$ cat /tmp/foobar.txt | awk '{print $2}' | grep database | grep -v `df -k |grep /dev/dsk | awk '{print $6}'` | wc -l
34

if [ `awk '{print $2}' /tmp/foobar.txt | grep database | grep -v 'df -k' |grep '/dev/dsk' | awk '{print $6}' | wc -l` -ne 0 ]; then echo "all devices are created on RAID10"; else echo "Some devices are created on non-RAID10"; fi

Too many grep-s, awk-s and cat-s - could be simplified with a single 'awk'

df -k |grep /dev/dsk | awk '{print $6}'

should return

/zeus1

In your example, you are using grep '/dev/dsk'
while I want to do grep -v /zeus1 (the latter is obtained from the first command I put)

thanks for your support

my guess is that you'll need to escape the inner backticks.. try it out and see if it works..

in my opinion it makes the code, well, a little difficult to understand and maintain by an average person, so i'd recommend so break it up a little.