Grepping issue..

I found another problem with my disk-adding script today. When looking for disks, I use grep.
When I grep for the following disk sizes:

5242880

I also pick up these as well:
524288000

How do I specifically pick out one or the other, using grep, without resorting to the -v option?

If I can't use grep, I'll have to totally revamp the script...

1) can you >grep "5242880 "
with an extra space at the end
2) or using whatever other character(s) might be proximate to the number

Would need to see the intermediate output.

Well, what I am doing is getting the disk size, and then setting it to a variable "$SIZE". Would the extra space work in that case?

Here is the code:

## Find your disk sizes available for use.
for i in `vxdisk -o alldgs list | grep -v -e DEVICE -e LVM -e invalid -e dg | awk '{print $1}'`
 do
 grep $i inq.fil | grep $DISKTYPE | awk -F ":" '{print $11}'
done | uniq -d > sizes.txt
TOTAL=`cat sizes.txt | wc -l`
if [ $TOTAL -eq 0 ]
  then
    echo "There are no disks of this type available."
    exit
 else
    continue
fi

## Present the sizes of the disks available.
print "Disk sizes that are available are:"
for i in `cat sizes.txt`
 do
 echo $i
done

##  Choose what size disk(s) you want to use.
echo "What size disk do you want to use?"
print -n "Disk size? :"
read SIZE

## Capture the disk size you chose for use later.
echo $SIZE > sizes.size
function avail_disk_func
         {
## Capture only the available disks of the type and size you want to use.
grep $DISKTYPE inq.fil | grep -v Copyright | grep $SIZE > $SIZE.txt
for i in `vxdisk -o alldgs list | grep -v -e DEVICE -e LVM -e invalid -e dg | awk '{print $1}'`
 do
 grep $i $SIZE.txt | grep $DISKTYPE | grep $SIZE
done > vxdisk_avail_$SIZE.txt
         }
avail_disk_func

## Capture how many disks are available for use.  If none, then exit.
TOTAL2=`cat vxdisk_avail_$SIZE.txt | wc -l`
if [ $TOTAL2 -eq 0 ]
 then
   echo "There are $TOTAL2 $DISKTYPE disks of this size available."
   exit
 else
   continue
fi
echo

## How many disks do you want to use?
echo "There are $TOTAL2 $DISKTYPE disks of this size available."
echo
echo "How many do you want to use?"
print -n "to create your diskgroup? :"
read NUMBER

Here is what the inq.fil file read from at the beginning of the code looks like:

Inquiry utility, Version 5.80     (SIL Version 2.8.2j)
Copyright (C) by EMC Corporation, all rights reserved.
For help type inq -h.

...............................................................................
----------------------------------------------------------------------------------------------------------------------------------
DEVICE             :SERIAL # :VEND    :PROD      :MODEL :REV  :BCV?:R? :CKD?:SM? :CAP(KB)  :BLKSZ:FC/UL?:PROTECTION  :SYMM SERIAL#
----------------------------------------------------------------------------------------------------------------------------------
/dev/rdsk/c0t6d0   :KN091774 :HP 36.4G:MAN3367MC :      :     :    :   :    :    :35566480 :1024 :      :            :
/dev/rdsk/c0t6d0s1 :KN091774 :HP 36.4G:MAN3367MC :      :     :    :   :    :    :512000   :1024 :      :            :
/dev/rdsk/c0t6d0s2 :KN091774 :HP 36.4G:MAN3367MC :      :     :    :   :    :    :34643968 :1024 :      :            :
/dev/rdsk/c0t6d0s3 :KN091774 :HP 36.4G:MAN3367MC :      :     :    :   :    :    :409600   :1024 :      :            :
/dev/rdsk/c1t2d0   : 2000/09 :HP      :DVD-ROM 30:      :     :    :   :    :    :         :1024 :      :            :
/dev/rdsk/c2t6d0   :KN091570 :HP 36.4G:MAN3367MC :      :     :    :   :    :    :35566480 :1024 :      :            :
/dev/rdsk/c6t6d0   :KN091754 :HP 36.4G:MAN3367MC :      :     :    :   :    :    :35566480 :1024 :      :            :
/dev/rdsk/c8t6d0   :KN091680 :HP 36.4G:MAN3367MC :      :     :    :   :    :    :35566480 :1024 :      :            :
/dev/rdsk/c10t0d1  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t0d2  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t0d3  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t0d4  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t0d5  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t0d6  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t0d7  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t1d0  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t1d1  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t1d2  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t1d3  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t1d4  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t1d5  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t2d1  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :5242880  :1024 :      :            :
/dev/rdsk/c10t2d2  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :5242880  :1024 :      :            :
/dev/rdsk/c10t2d3  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :5242880  :1024 :      :            :
/dev/rdsk/c12t2d1  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :5242880  :1024 :      :            :
/dev/rdsk/c12t2d2  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :5242880  :1024 :      :            :
/dev/rdsk/c12t2d3  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :5242880  :1024 :      :            :
/dev/rdsk/c14t2d1  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :5242880  :1024 :      :            :
/dev/rdsk/c14t2d2  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :5242880  :1024 :      :            :
/dev/rdsk/c14t2d3  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :5242880  :1024 :      :            :
/dev/rdsk/c16t2d1  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :5242880  :1024 :      :            :
/dev/rdsk/c16t2d2  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :5242880  :1024 :      :            :
/dev/rdsk/c16t2d3  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :5242880  :1024 :      :            :

Here is the output of the script being ran:

This script is only to be used when building NEW DISK GROUPS ONLY!!
that will be using VXVM 4.1 or higher to manage disks, with no rootdg.
This version has an option for striping, and lets you build multiple volumes
within the disk group(s) you create.

Have you ran the inq script?
Enter 'y' for Yes or 'n' for No :y

Chose the type of external storage
you will be working with.  Your choices
are 'EMC' and 'EVA' (EVA = HSV).

Enter 'EMC' or 'EVA'. Disk type? :eva


Disk sizes that are available are:
524288000  <-- There are 11 of these
5242880     <--  There are 3 of these
What size disk do you want to use?
Disk size? :5242880  <-- This is the size I want.  There are only 3

There are 14 HSV disks of this size available.  <--Incorrect number reported.

How many do you want to use?
to create your diskgroup? :

Rather than my trying to re-create your scenario, you are determining the number of each disk size from "vxdisk_avail_$SIZE.txt".
Can you post this file from your run? My thinking is to do something with a cut based on -d":" and then a numeric comparison.
But, I cannot work through all of the logic in my head.

Use grep with the -w option.

Regards

Perfect! Works great....Not sure why I didn't figure this one out...

Thanks.

Here is the output from both files:

vxdisk_avail_5242880.txt

root@server:/root_home> more vxdisk_avail_5242880.txt
/dev/rdsk/c10t2d1  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :5242880  :1024 :      :            :
/dev/rdsk/c10t2d2  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :5242880  :1024 :      :            :
/dev/rdsk/c10t2d3  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :5242880  :1024 :      :            :

vxdisk_avail_524288000.txt

root@server:/root_home> more vxdisk_avail_524288000.txt
/dev/rdsk/c10t0d6  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t0d7  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t1d0  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t1d1  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t1d2  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t1d3  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t1d4  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t1d5  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t1d6  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t1d7  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :
/dev/rdsk/c10t2d0  :5849ARF0 :COMPAQ  :HSV111 (C):      :     :    :   :    :    :524288000:1024 :      :            :

Previous message implied that you had solved the matter. Do you still need a way to differentiate values?

Thanks for your reply. I'll leave it to your discretion.

All it appears that you need is the device size, not the rest of the data when reporting number in that size category. So, I made sample1 and sample2 from your two files. I then ran the following script:

> cat numcomp
#! /bin/bash

cknum=5242880
count=0
echo $cknum

cat sample1 sample2 >sample3
cat sample3 | cut -d":" -f11 >sample4

echo "TRIAL #1"
cat sample4 | grep $cknum

echo "TRIAL #2"
cat sample4 | grep $cknum >sample5
while read zf
   do
#      echo $zf
      if [ $zf -eq $cknum ]
         then
            echo "Match "$zf
            count=$(($count + 1)) 
         else
            echo "Skipping "$zf
      fi
done <sample5

echo $count" occurences found of "$cknum

It generated output as follows:

So, pulling out to only have the size on each line allows through script to do the mathematical match to the number. While you already have another approach to solve the matter, I thought I'd follow-up and present this programming solution. A lot of the code could be eliminated when actually used, I just wanted to show the thought process.