I need useful command to match the string "/pci.../pci.../pci..../scsi..../disk..." with awk or sed? ( I need to put this command in my ksh script )

remark 1 [...] can be any string , and “pci pci pci scsi disk” are default strings remark 2 I have Solaris machine so syntax should fit Solaris

example

       prtpicl -v |grep :disk0 | awk '{print $2}'    

give the output

       /pci@0/pci@0/pci@2/scsi@0/disk@0 
link|improve this question

50% accept rate
1  
[...] can not be any string. it would probably be very bad if it were to contain /. – Daniel Beck Jan 17 at 11:35
feedback

1 Answer

up vote 0 down vote accepted
prtpicl -v \
| egrep ':disk0.*/pci[^/]+/pci[^/]+/pci[^/]+/scsi[^/]+/disk' \
| awk '{print $2}'

For example

$ cat prtpicl.out
Some headings blah blah
:disk0 some uninteresting stuff
:disk0 /pci@0/pci@0/pci@2/scsi@0/disk@0
:disk1 /pci@0/pci@0/pci@2/scsi@0/disk@1
Last line

$ cat prtpicl.out \
> | egrep ':disk0.*/pci[^/]+/pci[^/]+/pci[^/]+/scsi[^/]+/disk' \
> | awk '{print $2}'
/pci@0/pci@0/pci@2/scsi@0/disk@0
link|improve this answer
prtpicl -v | grep ':disk0.*/pci[^/]*/pci[^/]+/pci[^/]+/scsi[^/]+/disk' not match the /pci@0/pci@0/pci@2/scsi@0/disk@0 ? (I try it on my solaris machine ) – Eytan Jan 17 at 11:52
echo "/pci@0/pci@0/pci@2/scsi@0/disk@0" | egrep ':disk0.*/pci[^/]*/pci[^/]+/pci[^/]+/scsi[^/]+/disk' - its also not match on linux but I need this for my solaris machine – Eytan Jan 17 at 11:57
@Eytan: I don't have a Sun computer. What exactly is the output of prtpicl -v | grep disk0? – RedGrittyBrick Jan 17 at 12:02
prtpicl -v | grep disk0 GIVE YOU --> :disk0 /pci@0/pci@0/pci@2/scsi@0/disk@0 – Eytan Jan 17 at 12:06
@Eytan: It works for me. See updated answer. Maybe egrep on Sun boxen is different. I'll check my old Solaris manual later. – RedGrittyBrick Jan 17 at 12:35
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.