Operating System - HP-UX
1832660 Members
3152 Online
110043 Solutions
New Discussion

ksh / awk to parse "syminq" output ?

 
SOLVED
Go to solution
Stuart Abramson
Trusted Contributor

ksh / awk to parse "syminq" output ?

the output from EMC syminq looks like this:

/dev/rdsk/c13t0d0........EMC..SYMMETRIX..5568..84000000.......7680
/dev/rdsk/c13t3d1..M(4)..EMC..SYMMETRIX..5568..840C1000...35354880
/dev/rdsk/c13t3d2..M(4)..EMC..SYMMETRIX..5568..840C5000...35354880
/dev/rdsk/c13t3d3..M(4)..EMC..SYMMETRIX..5568..840C9000...35354880
/dev/rdsk/c13t3d4..M(4)..EMC..SYMMETRIX..5568..840CD000...35354880
/dev/rdsk/c13t3d5..M(4)..EMC..SYMMETRIX..5568..840D1000...35354880
/dev/rdsk/c13t3d6..M(4)..EMC..SYMMETRIX..5568..840D5000...35354880
/dev/rdsk/c13t7d0........EMC..SYMMETRIX..5568..8437A000....8838720
/dev/rdsk/c15t0d0........EMC..SYMMETRIX..5568..84000000.......7680

the 2nd field isn't always filled in. I want to parse the line using ksh or awk (NO PERL) so that the "EMC" field is always the 3rd field; even when the "M(X)" isn't present.

Can anyone tell me how to do that in ksh or awk, please?
11 REPLIES 11
RAC_1
Honored Contributor

Re: ksh / awk to parse "syminq" output ?

Do you want the lines, if thried filed is EMS, then do as follows.

syminq output | awk -F ".." '{if($3==EMC)print}'

Anil
There is no substitute to HARDWORK
Geoff Wild
Honored Contributor

Re: ksh / awk to parse "syminq" output ?

What are you trying to accomplish?

That ius, what data are you looking to get out of the syminq?

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Rodney Hills
Honored Contributor

Re: ksh / awk to parse "syminq" output ?

By deleting the M(4) with sed, everything should line up correctly and you can use awk from then on.

syminq output | sed -e 's/M(4)//' | awk -F ".." 'whatever you want to do'

HTH

-- Rod Hills
There be dragons...
John Poff
Honored Contributor

Re: ksh / awk to parse "syminq" output ?

Hi,

You could use the 'cut' command in a ksh script, or you could use the 'substr' function in awk.

JP
John Poff
Honored Contributor

Re: ksh / awk to parse "syminq" output ?

Here is a sample of how to do it in a ksh script with cut:

#!/usr/bin/ksh

# syminq.sh

while read LINE
do
DISK=$(echo $LINE | cut -c1-17)
MVAL=$(echo $LINE | cut -c20-23)
EMC=$(echo $LINE | cut -c26-28)

echo "DISK is $DISK"
echo "MVAL is $MVAL"
echo "EMC is $EMC"
done
(Assuming that your syminq output is in a file named syminq.txt).

JP
Stuart Abramson
Trusted Contributor

Re: ksh / awk to parse "syminq" output ?

Let me clarify a little:

1. I put "..." in to signify spaces. There are no "..." - there are spaces.

2. You can't use character positions because on differnet servers the field lengths are different. Also, if you have short device file names (c9t1d0) the spacing is (slightly) different than for long names (c22t14d7).

3. What I want to get out of this is a table which shows me that Symm device 0CD on Symm 84 has three device files, c13t3d1, c15t3d1 and c19t3d1, and is of type "M(4)" or "R1" and has size 8.8 GB.
Rodney Hills
Honored Contributor
Solution

Re: ksh / awk to parse "syminq" output ?

Don't get locked down into using field numbers. You can put the values into variables and make adjustments.

For example here is an awk-
dev=$1; m4=$2; emc=$3; sym=$4; siz=$7
if (m4 == "EMC") {
m4=""; emc=$2; sym=$3; siz=$6
}

Now the awk variables are adjusted depending on if M(4) exists and you can use them in your report.

HTH

-- Rod Hills
There be dragons...
Victor Fridyev
Honored Contributor

Re: ksh / awk to parse "syminq" output ?

Hi,
Let's assume that you have 10 fields in the records if the 2-nd field is OK and 9 fields if the field is empty.

awk 'NF==10 {print; next}
NF==9 {print $1,"RRR",$2,$3,$4,%5,$6,$7,$8,$9;next}' FILE

Instead of RRR you can use any replacement.
If NF is big, use "for" expression



HTH
Entities are not to be multiplied beyond necessity - RTFM
Geoff Wild
Honored Contributor

Re: ksh / awk to parse "syminq" output ?

Victor and Rodney's way should work.

Don't forget to assign points to everyone -

http://forums1.itrc.hp.com/service/forums/helptips.do?#28

http://forums1.itrc.hp.com/service/forums/pageList.do?userId=CA384034&listType=unassigned&forumId=1

Rgds...Geoff

Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
John Poff
Honored Contributor

Re: ksh / awk to parse "syminq" output ?

I used to do somthing similar with the 'inq' command, but the output from 'inq' had the fields separated by the colon ':' character, which made it easy to use awk with the -F: option to get the fields.

I don't have the latest version of syminq anymore but maybe there is an option to get it to produce the output with some character that you can use as a field separator?

JP
Tom Danzig
Honored Contributor

Re: ksh / awk to parse "syminq" output ?

You can access $1 as usual but use $(NF-1), $(NF-2), $(NF-3), etc to get the other data you need. Suppose you want the /dev/dsk field, the LUN S/N, and LUN capacity, use:

Use awk '/EMC/{printf("%s %s %s\n",$1,$(NF-2),$NF)}'.

This would work whether or not the M(4) field exists or not.