Computing.Net > Forums > Unix > awk help

awk help

Reply to Message Icon

Original Message
Name: Junes
Date: June 2, 2006 at 03:44:43 Pacific
Subject: awk help
OS: Unix
CPU/Ram: na
Model/Manufacturer: na
Comment:

Can someone help i need to write a script that will allow me to get the DriveName (i.e. Dr115 or Dr116) based on the DrvIndex valued calculated before.
vmoprcmd command give you the following information below.

DrvIndex DriveName
0 Dr115
1 Dr116

DriveName=`vmoprcmd | grep $DriveIndex | grep Dr | awk '{print $2}'`

I written the above code, but it give me Dr115 correctly, but when it goes to Dr116, it gives me DR115 and Dr116.

Dr115 is Down
Dr115
Dr116 is Down

Can someone provide some advice?


King Regards

Junes


Report Offensive Message For Removal

Response Number 1
Name: James Boothe
Date: June 5, 2006 at 15:00:21 Pacific
Subject: awk help
Reply: (edit)

Junes, your problem is that the grep looks at the entire line, so the grep for 1 finds the 1's in both DR115 and DR116.

We need to search just the first word for the desired value such as 0 or 1:

DriveName=`vmoprcmd | awk '$1=='$DriveIndex' {print $2}'`


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: awk help

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software