Operating System - HP-UX
1752282 Members
4718 Online
108786 Solutions
New Discussion юеВ

parse output from the following

 
SOLVED
Go to solution
kholikt
Super Advisor

parse output from the following

I have the following command output and I need to find a way that I can extract the Pseudo name and Logical device ID.

Pseudo name=emcpower259a
Logical device ID=0113
state=alive; policy=SymmOpt; priority=0; queued-IOs=0
==============================================================================
---------------- Host --------------- - Stor - -- I/O Path - -- Stats ---
### HW Path I/O Paths Interf. Mode State Q-IOs Errors
==============================================================================
3075 pci@8,600000/SUNW,qlc@1/fp@0,0 c2t5006048C53688940d132s0 FA 1cA active alive 0 0
3072 pci@8,600000/SUNW,qlc@2/fp@0,0 c3t5006048C5368894Fd132s0 FA 16cA active alive 0 0

Pseudo name=emcpower255a
Logical device ID=0117
state=alive; policy=SymmOpt; priority=0; queued-IOs=0
==============================================================================
---------------- Host --------------- - Stor - -- I/O Path - -- Stats ---
### HW Path I/O Paths Interf. Mode State Q-IOs Errors
==============================================================================
3075 pci@8,600000/SUNW,qlc@1/fp@0,0 c2t5006048C53688940d133s0 FA 1cA active alive 0 0
3072 pci@8,600000/SUNW,qlc@2/fp@0,0 c3t5006048C5368894Fd133s0 FA 16cA active alive 0 0


The output from the above will give just two column, first is the pseudo name and second is a logical device id

for example, the output from the above will be

259 0113
255 0117

notice that it also strip off the emcpowerxxxa from it too. Look like there is no simple way to do this in a shell script
abc
4 REPLIES 4
Mel Burslan
Honored Contributor
Solution

Re: parse output from the following

cat output|grep "Pseudo name" | cut -d"=" -f2 | sed -e "/emcpower/s/emcpower//"

This should give you 259a and 255a from the output above

cat output | grep "Logical device" |cut -d"=" -f2

output of the above should give you 0113 and 0117

Am I missing something ?
________________________________
UNIX because I majored in cryptology...
James R. Ferguson
Acclaimed Contributor

Re: parse output from the following

Hi:

One quick way:

# cat ./myfilter
#!/bin/sh
typeset FILE=$1
awk '
/Pseudo/ {split($0,a,"=");printf "%s", a[2]}
/Logica/ {split($0,a,"=");printf " %s\n", a[2]}
' ${FILE} | sed -e 's/[^ 0-9]*//g'

...using your input:

# ./myfilter myfile
259 0113
255 0117

...or:

# | ./myfilter

Regards!

...JRF...




./myfile


James R. Ferguson
Acclaimed Contributor

Re: parse output from the following

Hi (again):

Actually, in the spirit of conservation of needless processes (even in pipes), you could do:

# ./myfilter
#!/bin/sh
typeset FILE=$1
awk '
/Pseudo/ {split($0,a,"=");gsub(/[^ 0-9]*/,"",a[2]);printf "%s",a[2]}
/Logica/ {split($0,a,"=");gsub(/[^ 0-9]*/,"",a[2]);printf " %s\n",a[2]}
' ${FILE}

...that is, let 'awk' due all the work it is designed to do :-)

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: parse output from the following

Hi (again):

Are you satisfied with the help that you have received?

...JRF...