awk + sed + match complex string

0

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 

Eytan

Posted 2012-01-17T11:32:34.267

Reputation: 47

1[...] can not be any string. it would probably be very bad if it were to contain /. – Daniel Beck – 2012-01-17T11:35:11.263

Answers

0

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

RedGrittyBrick

Posted 2012-01-17T11:32:34.267

Reputation: 70 632

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 – 2012-01-17T11:52:13.800

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 – 2012-01-17T11:57:51.357

@Eytan: I don't have a Sun computer. What exactly is the output of prtpicl -v | grep disk0? – RedGrittyBrick – 2012-01-17T12:02:51.210

prtpicl -v | grep disk0 GIVE YOU --> :disk0 /pci@0/pci@0/pci@2/scsi@0/disk@0 – Eytan – 2012-01-17T12:06:27.737

@Eytan: It works for me. See updated answer. Maybe egrep on Sun boxen is different. I'll check my old Solaris manual later. – RedGrittyBrick – 2012-01-17T12:35:07.247