0

How can I print everything below after a trailing ===========

switchName:     GBL_A_SW1
switchType:     166.0
switchState:    Online
switchMode:     Native
switchRole:     Principal
switchDomain:   42
switchId:       fffb3a
switchWwn:      10:00:97:55:21:11:b7:c4
zoning:         ON (GBL_Fabric_A_Active)
switchBeacon:   OFF
FC Router:      OFF
HIF Mode:       OFF
Allow XISL Use: OFF
LS Attributes:  [FID: 128, Base Switch: No, Default Switch: Yes, Ficon Switch: No, Address Mode 0]

Index Slot Port Address Media  Speed        State    Proto
============================================================
   0    3    0   2a0040   id    N8        Online      FC  E-Port  (Trunk port, master is Slot  3 Port  1 )
   1    3    1   2a0140   id    N8        Online      FC  E-Port  10:00:c4:f5:7c:2c:1d:d8 "GBL_A_BAS384B" (downstream)(Trunk master)
   2    3    2   2a0240   id    N8        Online      FC  F-Port  1 N Port + 1 NPIV public
   3    3    3   2a0340   id    N4        Online      FC  F-Port  20:00:00:05:1e:0f:39:f3
   4    3    4   2a0440   id    N8        Online      FC  F-Port  20:0f:00:05:33:46:0d:90
   5    3    5   2a0540   id    N16       Online      FC  F-Port  20:21:00:02:ac:01:ea:1d
   6    3    6   2a0640   id    N16       Online      FC  E-Port  5c:4f:57:c4:33:15:ce:20 "fcr_fd_160" (downstream)(Trunk master)
   7    3    7   2a0740   id    N16       Online      FC  E-Port  (Trunk port, master is Slot  3 Port  6 )
   8    3    8   2a0840   id    N8        Online      FC  F-Port  50:01:73:80:31:2d:01:80
   9    3    9   2a0940   id    N8        Online      FC  F-Port  50:05:07:63:05:23:12:d1
  10    3   10   2a0a40   id    N8        Online      FC  F-Port  50:05:07:68:01:50:ef:47
  11    3   11   2a0b40   id    N16       Online      FC  F-Port  20:21:00:02:ac:01:c0:55
  12    3   12   2a0c40   id    N8        Online      FC  F-Port  10:00:8c:7c:ff:21:ab:12
  13    3   13   2a0d40   id    N8        Online      FC  F-Port  1 N Port + 3 NPIV public
  14    3   14   2a0e40   id    N4        Online      FC  F-Port  21:00:00:24:ff:25:f0:1e
  15    3   15   2a0f40   id    N16       Online      FC  F-Port  50:05:07:68:01:40:a7:28
 128    3   16   2a8040   id    N8        Online      FC  F-Port  21:00:00:24:ff:4e:76:ad
 129    3   17   2a8140   id    N8        Online      FC  F-Port  50:05:07:68:01:20:d6:f0
 130    3   18   2a8240   id    N4        Online      FC  F-Port  20:00:00:05:1e:0f:e1:d0

Like this

   0    3    0   2a0040   id    N8        Online      FC  E-Port  (Trunk port, master is Slot  3 Port  1 )
   1    3    1   2a0140   id    N8        Online      FC  E-Port  10:00:c4:f5:7c:2c:1d:d8 "GBL_A_BAS384B" (downstream)(Trunk master)
   2    3    2   2a0240   id    N8        Online      FC  F-Port  1 N Port + 1 NPIV public
   3    3    3   2a0340   id    N4        Online      FC  F-Port  20:00:00:05:1e:0f:39:f3
   4    3    4   2a0440   id    N8        Online      FC  F-Port  20:0f:00:05:33:46:0d:90
   5    3    5   2a0540   id    N16       Online      FC  F-Port  20:21:00:02:ac:01:ea:1d
   6    3    6   2a0640   id    N16       Online      FC  E-Port  5c:4f:57:c4:33:15:ce:20 "fcr_fd_160" (downstream)(Trunk master)
   7    3    7   2a0740   id    N16       Online      FC  E-Port  (Trunk port, master is Slot  3 Port  6 )
   8    3    8   2a0840   id    N8        Online      FC  F-Port  50:01:73:80:31:2d:01:80
   9    3    9   2a0940   id    N8        Online      FC  F-Port  50:05:07:63:05:23:12:d1
  10    3   10   2a0a40   id    N8        Online      FC  F-Port  50:05:07:68:01:50:ef:47
  11    3   11   2a0b40   id    N16       Online      FC  F-Port  20:21:00:02:ac:01:c0:55
  12    3   12   2a0c40   id    N8        Online      FC  F-Port  10:00:8c:7c:ff:21:ab:12
  13    3   13   2a0d40   id    N8        Online      FC  F-Port  1 N Port + 3 NPIV public
  14    3   14   2a0e40   id    N4        Online      FC  F-Port  21:00:00:24:ff:25:f0:1e
  15    3   15   2a0f40   id    N16       Online      FC  F-Port  50:05:07:68:01:40:a7:28
 128    3   16   2a8040   id    N8        Online      FC  F-Port  21:00:00:24:ff:4e:76:ad
 129    3   17   2a8140   id    N8        Online      FC  F-Port  50:05:07:68:01:20:d6:f0
 130    3   18   2a8240   id    N4        Online      FC  F-Port  20:00:00:05:1e:0f:e1:d0

Tried using awk '{print $0}' RS='==' data but details above ======== is still there and with a big gap.


Update:

So everything is now in place. However, i'm having a hard time concatenating the file. I have two files named sw_name and final_sw_name which consist of the data above and is being passed on to a variable.

When I tried to echoed it using this command
echo -e "$sw_name" > ${SW_TEMP}/TP; echo -e "\n final_sw_name >> ${SW_TEMP}/TP The $sw_name is being echoed on the file but not $final_sw_name.

Should be like this:

 Switch_Name
   0    3    0   2a0040   id    N8        Online      FC  E-Port  (Trunk port, master is Slot  3 Port  1 )
   1    3    1   2a0140   id    N8        Online      FC  E-Port  10:00:c4:f5:7c:2c:1d:d8 "GBL_A_BAS384B" (downstream)(Trunk master)
   2    3    2   2a0240   id    N8        Online      FC  F-Port  1 N Port + 1 NPIV public
   3    3    3   2a0340   id    N4        Online      FC  F-Port  20:00:00:05:1e:0f:39:f3
   4    3    4   2a0440   id    N8        Online      FC  F-Port  20:0f:00:05:33:46:0d:90
   5    3    5   2a0540   id    N16       Online      FC  F-Port  20:21:00:02:ac:01:ea:1d
   6    3    6   2a0640   id    N16       Online      FC  E-Port  5c:4f:57:c4:33:15:ce:20 "fcr_fd_160" (downstream)(Trunk master)
   7    3    7   2a0740   id    N16       Online      FC  E-Port  (Trunk port, master is Slot  3 Port  6 )
   8    3    8   2a0840   id    N8        Online      FC  F-Port  50:01:73:80:31:2d:01:80
   9    3    9   2a0940   id    N8        Online      FC  F-Port  50:05:07:63:05:23:12:d1
  10    3   10   2a0a40   id    N8        Online      FC  F-Port  50:05:07:68:01:50:ef:47
  11    3   11   2a0b40   id    N16       Online      FC  F-Port  20:21:00:02:ac:01:c0:55
  12    3   12   2a0c40   id    N8        Online      FC  F-Port  10:00:8c:7c:ff:21:ab:12
  13    3   13   2a0d40   id    N8        Online      FC  F-Port  1 N Port + 3 NPIV public
  14    3   14   2a0e40   id    N4        Online      FC  F-Port  21:00:00:24:ff:25:f0:1e
  15    3   15   2a0f40   id    N16       Online      FC  F-Port  50:05:07:68:01:40:a7:28
 128    3   16   2a8040   id    N8        Online      FC  F-Port  21:00:00:24:ff:4e:76:ad
 129    3   17   2a8140   id    N8        Online      FC  F-Port  50:05:07:68:01:20:d6:f0
 130    3   18   2a8240   id    N4        Online      FC  F-Port  20:00:00:05:1e:0f:e1:d0
Community
  • 1
  • 1
gafm
  • 351
  • 1
  • 9

3 Answers3

1

You may use this awk command:

awk 'p; /^=+$/{p=1}' file

   0    3    0   2a0040   id    N8        Online      FC  E-Port  (Trunk port, master is Slot  3 Port  1 )
   1    3    1   2a0140   id    N8        Online      FC  E-Port  10:00:c4:f5:7c:2c:1d:d8 "GBL_A_BAS384B" (downstream)(Trunk master)
   2    3    2   2a0240   id    N8        Online      FC  F-Port  1 N Port + 1 NPIV public
   3    3    3   2a0340   id    N4        Online      FC  F-Port  20:00:00:05:1e:0f:39:f3
   4    3    4   2a0440   id    N8        Online      FC  F-Port  20:0f:00:05:33:46:0d:90
   5    3    5   2a0540   id    N16       Online      FC  F-Port  20:21:00:02:ac:01:ea:1d
   6    3    6   2a0640   id    N16       Online      FC  E-Port  5c:4f:57:c4:33:15:ce:20 "fcr_fd_160" (downstream)(Trunk master)
   7    3    7   2a0740   id    N16       Online      FC  E-Port  (Trunk port, master is Slot  3 Port  6 )
   8    3    8   2a0840   id    N8        Online      FC  F-Port  50:01:73:80:31:2d:01:80
   9    3    9   2a0940   id    N8        Online      FC  F-Port  50:05:07:63:05:23:12:d1
  10    3   10   2a0a40   id    N8        Online      FC  F-Port  50:05:07:68:01:50:ef:47
  11    3   11   2a0b40   id    N16       Online      FC  F-Port  20:21:00:02:ac:01:c0:55
  12    3   12   2a0c40   id    N8        Online      FC  F-Port  10:00:8c:7c:ff:21:ab:12
  13    3   13   2a0d40   id    N8        Online      FC  F-Port  1 N Port + 3 NPIV public
  14    3   14   2a0e40   id    N4        Online      FC  F-Port  21:00:00:24:ff:25:f0:1e
  15    3   15   2a0f40   id    N16       Online      FC  F-Port  50:05:07:68:01:40:a7:28
 128    3   16   2a8040   id    N8        Online      FC  F-Port  21:00:00:24:ff:4e:76:ad
 129    3   17   2a8140   id    N8        Online      FC  F-Port  50:05:07:68:01:20:d6:f0
 130    3   18   2a8240   id    N4        Online      FC  F-Port  20:00:00:05:1e:0f:e1:d0
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • btw, is there a way i can grep this part `switchName: GBL_A_SW1` then next is this `awk 'p; /^=+$/{p=1}'`.. Tried a different combination but i couldn't get it. – gafm Jul 22 '19 at 15:13
  • 1
    Yes you can use: `awk 'p || /^switchName/ || p; /^=+$/{p=1}' file` – anubhava Jul 22 '19 at 15:16
  • so I was to achieve what is required however when i put it on a variable and echoed it. It's not printing as expected. It's printing but not with newline ` 0 3 0 2a0040 id N8 Online FC E-Port (Trunk port, master is Slot 3 Port 1 ) 1 3 1 2a0140 id N8 Online FC E-Port 10:00:c4:f5:7c:2c:1d:d8 "GBL_A_BAS384B" (downstream)(Trunk master) 2 3 2` – gafm Jul 23 '19 at 14:24
  • Code and data is not readable in comments. Better you edit your question and show your input data with attempted code. – anubhava Jul 23 '19 at 14:31
  • I don't understand how your command `echo -e "$sw_name" > ${SW_TEMP}/TP; echo -e "\n final_sw_name >> ${SW_TEMP}/TP The $sw_name` is related to my suggested `awk` command. – anubhava Jul 23 '19 at 15:42
1

Try:

sed '0,/========/ d' data

It deletes from the stream lines in range [0 .. the first line matched by regex ========] and then prints the rest of the stream normally.


Note that 0 start line is a GNU extension which means it may not be available on some systems. If you want to have a portable script, better use index 1 instead.

sed '1,/========/ d' data

The second solution won't work if characters ======= are in the first line, though.

If this may be the case, you can just insert an empty line at the start of the stream.

{ printf '\n' ; cat data ; } | sed '1,/========/ d'
Piotr Siupa
  • 3,929
  • 2
  • 29
  • 65
0

Try

awk 'BEGIN { RS="^==.*$"; } { print $0 ; }'
January
  • 16,320
  • 6
  • 52
  • 74
  • 1
    Defining `RS` to be an extended regular expression is an extension of GNU awk. According to Posix, `RS` is only a single character. – kvantour Jul 22 '19 at 13:41