In bash script from the output below, I need to print the lines between "Device #0" and "Device #1", but as all that is part of a bigger script I should use variables for start/stop lines.
----------------------------------------------------------------------
Physical Device information
----------------------------------------------------------------------
      Device #0
         Device is a Hard drive
         State                              : Online
         Block Size                         : 512 Bytes
         Supported                          : Yes
         Programmed Max Speed               : SATA 6.0 Gb/s
         Transfer Speed                     : SATA 6.0 Gb/s
         Reported Channel,Device(T:L)       : 0,0(0:0)
         Reported Location                  : Connector 0, Device 0
         Vendor                             : ATA
         Model                              :
         Firmware                           : 003Q
         Serial number                      : S2HTNX0H418779
         World-wide name                    : 5002538C402805A4
         Reserved Size                      : 265496 KB
         Used Size                          : 897129 MB
         Unused Size                        : 18327 MB
         Total Size                         : 915715 MB
         Write Cache                        : Enabled (write-back)
         FRU                                : None
         S.M.A.R.T.                         : No
         S.M.A.R.T. warnings                : 0
         Power State                        : Full rpm
         Supported Power States             : Full power,Powered off
         SSD                                : Yes
         Temperature                        : 39 C/ 102 F
         NCQ status                         : Enabled
      ----------------------------------------------------------------
      Device Phy Information
      ----------------------------------------------------------------
         Phy #0
            PHY Identifier                  : 0
            SAS Address                     : 30000D1701801803
            Attached PHY Identifier         : 3
            Attached SAS Address            : 50000D1701801800
      ----------------------------------------------------------------
      Runtime Error Counters
      ----------------------------------------------------------------
         Hardware Error Count               : 0
         Medium Error Count                 : 0
         Parity Error Count                 : 0
         Link Failure Count                 : 0
         Aborted Command Count              : 0
         SMART Warning Count                : 0
Model, SSD
----------------------------------------------------------------------
Physical Device information
----------------------------------------------------------------------
      Device #1
         Device is a Hard drive
         State                              : Online
         Block Size                         : 512 Bytes
         Supported                          : Yes
         Programmed Max Speed               : SATA 6.0 Gb/s
         Transfer Speed                     : SATA 6.0 Gb/s
         Reported Channel,Device(T:L)       : 0,0(0:0)
         Reported Location                  : Connector 0, Device 0
         Vendor                             : ATA
         Model                              :
         Firmware                           : 003Q
         Serial number                      : S2HTNX0H418779
         World-wide name                    : 5002538C402805A4
         Reserved Size                      : 265496 KB
         Used Size                          : 897129 MB
         Unused Size                        : 18327 MB
         Total Size                         : 915715 MB
         Write Cache                        : Enabled (write-back)
         FRU                                : None
         S.M.A.R.T.                         : No
         S.M.A.R.T. warnings                : 0
         Power State                        : Full rpm
         Supported Power States             : Full power,Powered off
         SSD                                : Yes
         Temperature                        : 39 C/ 102 F
         NCQ status                         : Enabled
      ----------------------------------------------------------------
      Device Phy Information
      ----------------------------------------------------------------
         Phy #0
            PHY Identifier                  : 0
            SAS Address                     : 30000D1701801803
            Attached PHY Identifier         : 3
            Attached SAS Address            : 50000D1701801800
      ----------------------------------------------------------------
      Runtime Error Counters
      ----------------------------------------------------------------
         Hardware Error Count               : 0
         Medium Error Count                 : 0
         Parity Error Count                 : 0
         Link Failure Count                 : 0
         Aborted Command Count              : 0
         SMART Warning Count                : 0
Model, SSD
----------------------------------------------------------------------
Physical Device information
----------------------------------------------------------------------
      Device #2
         Device is a Hard drive
         State                              : Online
         Block Size                         : 512 Bytes
         Supported                          : Yes
         Programmed Max Speed               : SATA 6.0 Gb/s
         Transfer Speed                     : SATA 6.0 Gb/s
         Reported Channel,Device(T:L)       : 0,0(0:0)
         Reported Location                  : Connector 0, Device 0
         Vendor                             : ATA
         Model                              :
         Firmware                           : 003Q
         Serial number                      : S2HTNX0H418779
         World-wide name                    : 5002538C402805A4
         Reserved Size                      : 265496 KB
         Used Size                          : 897129 MB
         Unused Size                        : 18327 MB
         Total Size                         : 915715 MB
         Write Cache                        : Enabled (write-back)
         FRU                                : None
         S.M.A.R.T.                         : No
         S.M.A.R.T. warnings                : 0
         Power State                        : Full rpm
         Supported Power States             : Full power,Powered off
         SSD                                : Yes
         Temperature                        : 39 C/ 102 F
         NCQ status                         : Enabled
      ----------------------------------------------------------------
      Device Phy Information
      ----------------------------------------------------------------
         Phy #0
            PHY Identifier                  : 0
            SAS Address                     : 30000D1701801803
            Attached PHY Identifier         : 3
            Attached SAS Address            : 50000D1701801800
      ----------------------------------------------------------------
      Runtime Error Counters
      ----------------------------------------------------------------
         Hardware Error Count               : 0
         Medium Error Count                 : 0
         Parity Error Count                 : 0
         Link Failure Count                 : 0
         Aborted Command Count              : 0
         SMART Warning Count                : 0
Model, SSD
In this case the output for Device #0 to Device #2 is the same, but it doesn't really matter for the test.
So trying with cat arcconf | awk '/Device #0/,/Device #1/' where the output above is stored in a file called arcconf works. But trying to use variables instead of 0 and 1 doesn't work at all:
MIN_INDEX=0
INDEX=1
cat arcconf | awk '/Device #"$MIN_INDEX"/,/Device #"$INDEX"/'
cat arcconf | sed -n -e "/Device #"$INDEX_MIN"$/,/Device #"$INDEX"$/{ /Device #"$INDEX_MIN"$/d; /Device #"$INDEX"$/d; p; }"
It doesn't display anything. Could you please help.
Also as I am going to use the output from Device to Device lines several times, is it possible to store it in some new variable which I should use in the future?
Thanks, Valentina
 
     
     
    