The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
TAHI Test Suite 3.0.13 (IPv6 Conformance Test Tool branch) iBot Software Releases - RSS News 0 04-06-2008 01:20 PM
test and .test in same directory vikashtulsiyan SUN Solaris 14 12-28-2007 02:25 AM
Keithley Introduces Linux-Based RF Parametric Test Systems - Test and Measurement.com iBot UNIX and Linux RSS News 0 07-23-2007 11:30 AM
Test Help!!!!!! Xskwizitboi UNIX for Dummies Questions & Answers 1 12-02-2004 01:35 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-04-2008
melanie_pfefer melanie_pfefer is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 234
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 (permalink)  
Old 04-04-2008
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

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 (permalink)  
Old 04-04-2008
melanie_pfefer melanie_pfefer is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 234
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 (permalink)  
Old 04-04-2008
ag79 ag79 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 33
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:21 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0