Grepping issue..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grepping issue..
# 1  
Old 02-27-2008
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...
# 2  
Old 02-27-2008
Question grepping

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.
# 3  
Old 02-27-2008
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:

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:
Code:
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:
Code:
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? :

# 4  
Old 02-27-2008
Question want to see an intermediate file

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.
# 5  
Old 02-27-2008
Use grep with the -w option.

Regards
# 6  
Old 02-27-2008
Quote:
Originally Posted by Franklin52
Use grep with the -w option.

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

Thanks.
# 7  
Old 02-27-2008
Quote:
Originally Posted by joeyg
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.

Here is the output from both files:

vxdisk_avail_5242880.txt

Code:
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

Code:
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 :      :            :

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Performance issue in Grepping large files

I have around 300 files(*.rdf,*.fmb,*.pll,*.ctl,*.sh,*.sql,*.prog) which are of large size. Around 8000 keywords(which will be in the file $keywordfile) needed to be searched inside those files. If a keyword is found in a file..I have to insert the filename,extension,catagoery,keyword,occurrence... (8 Replies)
Discussion started by: millan
8 Replies

2. Shell Programming and Scripting

Grepping more than one word

Dear Experts, Need your help. Typically we use "grep" to search and display a pattern in a txt file. However, here what we want is, we want to grep a line which contains 4 words any where in a line. For example. File has 10,000,000 lines in it out of which there is a particular line which... (1 Reply)
Discussion started by: anushree.a
1 Replies

3. UNIX for Dummies Questions & Answers

Grepping using -w and dashes (-)

I have a script to sort a list of arbitrary hosts and determine if they are supported by grepping them into a master supported list. I cut all the suffixes of the hosts in the arbitrary list, leaving the "short" hostname if you will, then grep -w them into the master list. For example: ... (1 Reply)
Discussion started by: MaindotC
1 Replies

4. Shell Programming and Scripting

grepping by digit

Hi all, Need your help here. I have a file with thousand of lines, as shown in example below KDKJAA 98324 OIDSAJ 324 KJAJAK 100 KJKAJK 89 JOIJOI 21 JDKDJL 12 UOIUOD 10 UDUYDS 8 UIUHKK 6 I would like to grep using... (5 Replies)
Discussion started by: masterpiece
5 Replies

5. UNIX for Dummies Questions & Answers

grepping a variable

I need to pass a parameter that will then be grepped. I need it to grep /paramater and then have a space so if 123 was passed my grep would be grep '/123 ' sample.log this works fine from the command line but when i try and set it searchThis="/$2 " and then run grep $searchThis... (6 Replies)
Discussion started by: magnia
6 Replies

6. UNIX for Dummies Questions & Answers

Help with grepping within variables

I've got a script at the moment that looks like this: if then echo "How many hours would you like users to have logged in for? (single digits)" read hours tim= echo "These are the users who were logged in for $hours... (1 Reply)
Discussion started by: chris_rabz
1 Replies

7. Shell Programming and Scripting

Please help on grepping

Hi All, I have a log file and I want to parse the logfile with a script.A sample text is shown below: I would grep on "return code " on this file. Any idea how the lines above and below the grep patterns could also be extracted. Thanks! nua7 The runLoggingInstall return code is 0... (3 Replies)
Discussion started by: nua7
3 Replies

8. Shell Programming and Scripting

grepping around

Using shell scripts, I use grep to find the word “error” in a log file: grep error this.log. How can I print or get the line 3 lines below the line that word “error” is located? Thanks in advance for your response. (9 Replies)
Discussion started by: cbeauty
9 Replies

9. UNIX for Dummies Questions & Answers

grepping for a sentence

Can you grep for a sentence. I have to search logs everyday at work and I was wondering if I could search for a string of words instead of just one. for example, if I had to find this sentence: "Received HTTP message type" How would I grep it (2 Replies)
Discussion started by: eloquent99
2 Replies

10. UNIX for Dummies Questions & Answers

grepping

Is there a way to grep for something and then print out 10 lines after it. for example if I want to grep for a word, then output the following 10 or whatever number of lines after the word. (5 Replies)
Discussion started by: eloquent99
5 Replies
Login or Register to Ask a Question