test wordcount


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting test wordcount
# 1  
Old 04-04-2008
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
# 2  
Old 04-04-2008
Code:
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'
# 3  
Old 04-04-2008
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
# 4  
Old 04-04-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shc : trying to test functionality "test" compiling but can not execute

I am testing shc to see if it would help with my need. Im at a point where Im trying to compile and test the "test.ksh" file that comes in the tar ball : shc-3.8.9> shc -v -r -f test.ksh shc shll=ksh shc =-c shc =exec '%s' "$@" shc = shc opts= shc: cc test.ksh.x.c -o test.ksh.x... (7 Replies)
Discussion started by: popeye
7 Replies

2. Shell Programming and Scripting

Prefixing test case methods with letter 'test'

Hi, I have a Python unit test cases source code file which contains more than a hundred test case methods. In that, some of the test case methods already have prefix 'test' where as some of them do not have. Now, I need to add the string 'test' (case-sensitive) as a prefix to those of the... (5 Replies)
Discussion started by: royalibrahim
5 Replies

3. Shell Programming and Scripting

Help with wordcount

Hi, this is my first post so bare with me I have a file which I want to count the amounts of the same line in the file and display by using a shell script for example file1 apple apple apple. bananasi would like the output to be apple 2 apple. 1 bananas 1however, i need this... (2 Replies)
Discussion started by: legolad
2 Replies

4. UNIX for Dummies Questions & Answers

Math with wordcount output

Hi I know very little about unix. I have a unix code (which I'm running in geektools) which gives me the word count of a pages document. However, the pages document innately contains 522 words of superfluous "Ipsem Lorem..." text which are included in the count. How would I go about... (4 Replies)
Discussion started by: eunoia7
4 Replies

5. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

6. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies
Login or Register to Ask a Question