The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Compare two arrays in sh or compare two fields rijeshpp Shell Programming and Scripting 0 10-31-2007 02:47 AM
how to exclude the GREP command from GREP yamsin789 UNIX for Advanced & Expert Users 2 10-05-2007 02:59 AM
Make grep -c display like grep -n? Jerrad Shell Programming and Scripting 2 08-25-2006 12:20 AM
How to compare it ?? sabercats Shell Programming and Scripting 4 02-16-2006 06:07 PM
LPP Compare Smoker AIX 2 06-09-2005 01:43 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-15-2005
k@ssidy k@ssidy is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 31
compare grep?

is there any way to compare two grep commands in an if statement? like:

if grep blah = grep blah blah
then

is there a way to store the values of the greps and compare them? the greps are counting pattern matches in two different files and i need to make sure they match.
  #2 (permalink)  
Old 06-15-2005
Just Ice's Avatar
Just Ice Just Ice is offline Forum Advisor  
Lights on, brain off.
  
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 637
why don't you just diff the fiiles? see "man diff" ....
  #3 (permalink)  
Old 06-15-2005
k@ssidy k@ssidy is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 31
i guess i wasn't specific enough, the compare is a little complicated. In one file i am counting the instances of the pattern with grep -c and i want to compare that count to the value in field 3 of another file where field 1 = C

so, let me try to explain a little easier, i want to compare the values of these two statements:

grep -c <pattern> <file>
grep "^C" <file> | awk -F'|' '{print $3}'

if there is an easier way to do this i'm all ears, i don't even know if this is possible to begin with so any input is appreciated
  #4 (permalink)  
Old 06-15-2005
Just Ice's Avatar
Just Ice Just Ice is offline Forum Advisor  
Lights on, brain off.
  
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 637
sounds simple enough ... just to confirm, can you post a line from the second file?
  #5 (permalink)  
Old 06-15-2005
k@ssidy k@ssidy is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 31
C| |00000009| |00000000|

so in other words, i'm counting in one file the number of time s pattern comes up and i want to see if that number matches the number in field 3, in this case it's 9, do I have to account for the leading zeros in the field when comparing?
  #6 (permalink)  
Old 06-15-2005
Just Ice's Avatar
Just Ice Just Ice is offline Forum Advisor  
Lights on, brain off.
  
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 637
not required ... treat both of them like numbers ....

Code:
#! /bin/ksh

InstCount=$(grep -c pattern file1)
ReqdCount=$(awk -F"|" '/^C/ {print $3}' file2)

if [ $InstCount -eq $ReqdCount ]
then
    echo "Counts are the same."
else
    echo "Somebody fibbed on the count."
fi

exit 0
  #7 (permalink)  
Old 06-15-2005
marquis marquis is offline
Registered User
  
 

Join Date: Jan 2004
Posts: 12
you can do this ( in bash )

c=`grep foo fil1`
d=`grep bar fil2`

if [ "$c" == "$d" ]; then
...
else
...
fi

HTH
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 02:20 AM.


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