Operating System - HP-UX
1832921 Members
2719 Online
110048 Solutions
New Discussion

Re: Using grep to get some information

 
SOLVED
Go to solution
Keith Zuidema_1
Advisor

Using grep to get some information

Hello I am trying to write script that lists the slots 1-10 , 11-20, etc. the input is the info below, I have tried grep in many diffrent forms, but am having no luck.

MT_slot_1 EMPTY
IE_slot_1 EMPTY
IE_slot_2 EMPTY
DT_slot_1 EMPTY
DT_slot_2 EMPTY
DT_slot_3 EMPTY
DT_slot_4 EMPTY
ST_slot_1 FULL CLN001
ST_slot_2 FULL 568
ST_slot_3 FULL 569
ST_slot_4 FULL 566
ST_slot_5 FULL 576
ST_slot_6 FULL 570
ST_slot_7 FULL 571
ST_slot_8 FULL 572
ST_slot_9 FULL 573
ST_slot_10 FULL 574
ST_slot_11 FULL 575
ST_slot_12 FULL 538
ST_slot_13 FULL 532
ST_slot_14 FULL 524
ST_slot_15 FULL 523
ST_slot_16 FULL 522
ST_slot_17 FULL 521
ST_slot_18 FULL 520
ST_slot_19 FULL 519
ST_slot_20 FULL 518

for example
mc -p /dev/rac/c13t0d0 -rDISM | grep ST_slot_/[1-2]
returns --
ST_slot_1 FULL CLN001
ST_slot_2 FULL 568
ST_slot_10 FULL 574
ST_slot_11 FULL 575
ST_slot_12 FULL 538
ST_slot_13 FULL 532
ST_slot_14 FULL 524
ST_slot_15 FULL 523
ST_slot_16 FULL 522
ST_slot_17 FULL 521
ST_slot_18 FULL 520
ST_slot_19 FULL 519
ST_slot_20 FULL 518
ST_slot_21 FULL 517
ST_slot_22 FULL 516
ST_slot_23 FULL 515
ST_slot_24 FULL 514
ST_slot_25 FULL 513
ST_slot_26 FULL 537
ST_slot_27 FULL 536
ST_slot_28 FULL 535
ST_slot_29 FULL 534

Any help would be great. I have attached a txt document with some of the above if anyone wants to give it a try.
4 REPLIES 4
Keith Zuidema_1
Advisor

Re: Using grep to get some information

I have tried
mc -p /dev/rac/c13t0d0 -rDISM | grep ST_slot_[1-2]

mc -p /dev/rac/c13t0d0 -rDISM | grep -e ST_slot_1 -e ST_slot_2

mc -p /dev/rac/c13t0d0 -rDISM | grep ST_slot_[10-20]
James R. Ferguson
Acclaimed Contributor
Solution

Re: Using grep to get some information

Hi:

I'd probably use 'sed', 'awk' or Perl and look for ranges as you appear to want:

# sed -ne '/slot_1[ ]/,/slot_10/p' file

# sed -ne '/slot_10[ ]/,/slot_20/p' file

...or if you only want the "FULL" and not the "EMPTY" ones:

# sed -ne '/slot_1[ ]F/,/slot_10/p' file

I used the '[ ]' to surround a space for readability, here.

Regards!

...JRF...
Keith Zuidema_1
Advisor

Re: Using grep to get some information

Thank you JRF worked perfectly. Points assigned
Dennis Handly
Acclaimed Contributor

Re: Using grep to get some information

If your file isn't sorted you would need lots of patterns:
mc -p /dev/rac/c13t0d0 -rDISM |
grep -e "ST_slot_[1-9] " -e "ST_slot_1[0-9] " -e "ST_slot_20 "

>JRF: I'd probably use 'sed', 'awk' or Perl and look for ranges as you appear to want:

I think the ranges are in the patterns and not the data?