Formatting grep and awk output

Hi there. I have a very large file and I am trying to format it so that I can pull out certain pieces of data/info and report it in spreadsheet format/style.

The file has ###### which will separate each line that will be listed in the spreadsheet. Whenever I find "No" at the end of a line I want to be able to print info from the previous lines before finding the No. I want to be able to print second and third entry on the line previous lines with the "=" and then the Director Identification, the Director Port all on one line in a spreadsheet format.

I'm sure this can be done using awk programming but I am really struggling to find the correct syntax to use. My main problem has to do with pulling data that is ahead of finding the "No". You will see that in my extract below that in the first set of data between the ##### that the No appears on the last line so the Director Identification and Port will be the ones just above that No where as in the next set of data the No is not the last line....

For example in the extract from the file below I want the output to be

SEIDBABAK01_212E4_VMAX2673 10000000c93212e4 FA13e1 FA-8F 0 
POST07_HBA_1_VMAX2673_FA_5F1 10000000c93d51d7 FA-5E 0

Below is the extract from the file...

="SEIDBABAK01",="SEIDBABAK01_212E4_VMAX2673_FA13e1",="10000000c93212e4",="SEI_FABRIC_1_BOTTOM",="Switch_9"

Symmetrix ID            : 000192602673

Director Identification : FA-13E
Director Port           : 1

                            User-generated                      Logged On
Identifier       Type  Node Name        Port Name        FCID   In     Fabric
---------------- ----- --------------------------------- ------ ------ ------
10000000c93212e4 Fibre 10000000c93212e4 10000000c93212e4 618180 Yes    Yes

Director Identification : FA-8F
Director Port           : 0

                            User-generated                      Logged On
Identifier       Type  Node Name        Port Name        FCID   In     Fabric
---------------- ----- --------------------------------- ------ ------ ------
10000000c93212e4 Fibre 10000000c93212e4 10000000c93212e4 618180 No     No

####################################################



BLANK,="POST07_HBA_1_VMAX2673_FA_5F1",="10000000c93d51d7",="SEI_FABRIC_2_TOP",="Switch_10"

Symmetrix ID            : 000192602673

Director Identification : FA-5E
Director Port           : 0

                            User-generated                      Logged On
Identifier       Type  Node Name        Port Name        FCID   In     Fabric
---------------- ----- --------------------------------- ------ ------ ------
10000000c93d51d7 Fibre 10000000c93d51d7 10000000c93d51d7 680913 No     No

Director Identification : FA-5F
Director Port           : 1

                            User-generated                      Logged On
Identifier       Type  Node Name        Port Name        FCID   In     Fabric
---------------- ----- --------------------------------- ------ ------ ------
10000000c93d51d7 Fibre 10000000c93d51d7 10000000c93d51d7 680913 No     Yes

####################################################

what have you tried in awk? If you can post that we can try to correct it..

Yes: post what you've tried so far. And, how does that FA13e1 end up in your sample output?

Thanks guys for your replies.

I need to simplify this a bit I think. What I am really trying to do is print information from the lines above when "No" is matched as the 6th entry in the line that has "Fibre" in it. So when No is matched on $6 I want to print the

Director Identification : FA-8F
Director Port           : 0

Where the line that contains the word "Fibre" looks like

10000000c93212e4 Fibre 10000000c93212e4 10000000c93212e4 618180 No     No

So from the extract of the file that I posted I can easily filter out the "Fibre" and "No" using something like the following command

cat <filename> | awk '/\=|Director Identification|Director Port|Fibre/ {print $0}' |  awk '{ if (NF ==7 && $6=="No") print$1}'

which prints $1 from that line and obviously I can print anything I want from that line. But when I get a "No" in $6 I want to be able to print the

Director Identification : FA-8F
Director Port           : 0

from the lines just above the line with the "No".

I am really just struggling with trying to filter out data that is in lines above the matched text with "No" in $6.

Once I filer it out I won't have a problem with formatting the output the way I want it.

---------- Post updated at 05:34 PM ---------- Previous update was at 11:59 AM ----------

I have figured out a way around this. I reformatted the file so that I could filter out what I need. It gives me what I need for now. I would still like to know a way to print previous lines in a file when a field entry is matched on a later line. Anyway this is the awk code I used. Not very pretty but it works...

cat 2673_nologin_check.out | sed '/\#/d' | sed '/User-generated/d' | sed '/Symmetrix ID/d' | sed '/FCID/d' | sed '/\-\-\-/d' | sed '/^$/d' | sed '/\=\"/d' | sed 's/Director Identification \: //g' | sed 's/Director Port           \://g' | sed '/^$/d' | nawk '{ORS=NR%3?FS:RS}{print$0}' | awk '/No$/ {print$1,$2,$3}'

Which generates output like

FA-8F 0 10000000c93212e4
FA-5E 0 10000000c93d51d7
FA-8E 0 10000000c93d543c
FA-8F 0 10000000c940c25f
FA-10H 0 10000000c940c704
FA-5F 0 10000000c940d225
FA-6G 0 10000000c9418749
awk -F"[, ]" '$0!~/./{next}/,/{gsub(/[="]*/,z);x=$2 OFS $3}/r Id|r Po/&&x{x=x OFS $NF}$NF=="No"{print x;x=z}'  yourfile

Make sure it fits with your expectations, or feel free to adjust to your requirements.
What i get is like :

$ cat tst
="SEIDBABAK01",="SEIDBABAK01_212E4_VMAX2673_FA13e1",="10000000c93212e4",="SEI_FABRIC_1_BOTTOM",="Switch_9"

Symmetrix ID            : 000192602673

Director Identification : FA-13E
Director Port           : 1

                            User-generated                      Logged On
Identifier       Type  Node Name        Port Name        FCID   In     Fabric
---------------- ----- --------------------------------- ------ ------ ------
10000000c93212e4 Fibre 10000000c93212e4 10000000c93212e4 618180 Yes    Yes

Director Identification : FA-8F
Director Port           : 0

                            User-generated                      Logged On
Identifier       Type  Node Name        Port Name        FCID   In     Fabric
---------------- ----- --------------------------------- ------ ------ ------
10000000c93212e4 Fibre 10000000c93212e4 10000000c93212e4 618180 No     No

####################################################



BLANK,="POST07_HBA_1_VMAX2673_FA_5F1",="10000000c93d51d7",="SEI_FABRIC_2_TOP",="Switch_10"

Symmetrix ID            : 000192602673

Director Identification : FA-5E
Director Port           : 0

                            User-generated                      Logged On
Identifier       Type  Node Name        Port Name        FCID   In     Fabric
---------------- ----- --------------------------------- ------ ------ ------
10000000c93d51d7 Fibre 10000000c93d51d7 10000000c93d51d7 680913 No     No

Director Identification : FA-5F
Director Port           : 1

                            User-generated                      Logged On
Identifier       Type  Node Name        Port Name        FCID   In     Fabric
---------------- ----- --------------------------------- ------ ------ ------
10000000c93d51d7 Fibre 10000000c93d51d7 10000000c93d51d7 680913 No     Yes

####################################################
$ awk -F"[, ]" '$0!~/./{next}/,/{gsub(/[="]*/,z);x=$2 OFS $3}/r Id|r Po/&&x{x=x OFS $NF}$NF=="No"{print x;x=z}' tst
SEIDBABAK01_212E4_VMAX2673_FA13e1 10000000c93212e4 FA-13E 1 FA-8F 0
POST07_HBA_1_VMAX2673_FA_5F1 10000000c93d51d7 FA-5E 0
$

Note that :
a) the code does not print to the last "No" before the #### but
until it meet the first "No"
b) you can also enforce the code by adding a cleanup condition of x variable like /####/{x=z}

$ awk -F"[, ]" '$0!~/./{next}/,/{gsub(/[="]*/,z);x=$2 OFS $3}/r Id|r Po/&&x{x=x (/r Po/?":":OFS) $NF}$NF=="No"{print x;x=z}' tst
SEIDBABAK01_212E4_VMAX2673_FA13e1 10000000c93212e4 FA-13E:1 FA-8F:0
POST07_HBA_1_VMAX2673_FA_5F1 10000000c93d51d7 FA-5E:0

It shouldn't print FA-13E 1 , should it? As it is followed by a YES. Try this:

awk     '!A[1] && NF>0          {m=split ($0, T, "\"")          # save relevant fields
                                 A[1]=T[m-7]
                                 A[2]=T[m-5]}
         /Director Id/          {A[3]=$NF}                      # save Ident
         /Director Po/          {A[4]=$NF}                      # save Port
         /User-gene/            {A[5]=NR+3}                     # get line No. of switch
         NR==A[5] && $NF=="No"  {A[6]=1}                        # save switch info from that line
         /^#+$/ && A[6]         {print A[1],A[2],A[3],A[4]      # print if record end and switch was "No"
                                 delete A}                      # clear the info retained; new record
        '  file
SEIDBABAK01_212E4_VMAX2673_FA13e1 10000000c93212e4 FA-8F 0
POST07_HBA_1_VMAX2673_FA_5F1 10000000c93d51d7 FA-5F 1

If FA-13E 1 is not expected you can give a try to

$ awk -F"[, ]" '$0!~/./{next}/,/{gsub(/[="]*/,z);x=$2 OFS $3}/r Id|r Po/{y=y (/r Po/?":":OFS) $NF}$NF=="No"{print x y;x=z}/Fibre/{y=z}' tst
SEIDBABAK01_212E4_VMAX2673_FA13e1 10000000c93212e4 FA-8F:0
POST07_HBA_1_VMAX2673_FA_5F1 10000000c93d51d7 FA-5E:0
$ awk -F"[, ]" '$0!~/./{next}/,/{gsub(/[="]*/,z);x=$2 OFS $3}/r Id|r Po/{y=y OFS $NF}$NF=="No"{print x y;x=z}/Fibre/{y=z}' tst
SEIDBABAK01_212E4_VMAX2673_FA13e1 10000000c93212e4 FA-8F 0
POST07_HBA_1_VMAX2673_FA_5F1 10000000c93d51d7 FA-5E 0
$

Thanks guys for the posts. You are correct when you say that "FA 13E 1" should not be printed. I have this working the way I need it now using

nawk -F"[, ]" '$0!~/./{next}/,/{gsub(/[="]*/,z);x=$2 OFS $3}/r Id|r Po/{y=y OFS $NF}$NF=="No"{print x y;x=z}/Fibre/{y=z}'