Extract a string that is located above and nearest to the matching pattern in a multiline output
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
Below is the HP ssacli command to see configured hardware RAID details:
ssacli ctrl slot=0 show config
and its output is as below:
HPE Smart Array P408i-a SR Gen10 in Slot 0 (Embedded)
Internal Drive Cage at Port 1I, Box 1, OK
Internal Drive Cage at Port 2I, Box 0, OK
Port Name: 1I (Mixed)
Port Name: 2I (Mixed)
Array A (Solid State SAS, Unused Space: 0 MB)
logicaldrive 1 (447.10 GB, RAID 1, OK)
physicaldrive 1I:1:1 (port 1I:box 1:bay 1, SAS SSD, 480 GB, OK)
physicaldrive 1I:1:2 (port 1I:box 1:bay 2, SAS SSD, 480 GB, OK)
SEP (Vendor ID HPE, Model Smart Adapter) 379 (Port: Unknown)
I have to figure out the Array name in order to delete it by searching for the matching disk info which I get as input from the user. For example, if the disk input is 1I:1:1 then I have to search for this string in the output of the above command. Since this disk is available and matching, I have to extract the Array name (here it is 'A') and once I get this Array parameter then I can go ahead delete this existing RAID configuration.
ssacli ctrl slot=0 show config | grep -B 4 '1I:1:1' | grep Array | awk 'print $2'
The problem with the above command is,
value 4 in the grep -B cannot be always constant as the matching disk may come first, second or third or so on under an Array in the output.
there may be multiple RAID array configurations available in the output, so there may be Array A, B, C etc., I have to find and retrieve the nearest "Array" string that matches my input disk
shell-script text-processing raid
add a comment |Â
up vote
0
down vote
favorite
Below is the HP ssacli command to see configured hardware RAID details:
ssacli ctrl slot=0 show config
and its output is as below:
HPE Smart Array P408i-a SR Gen10 in Slot 0 (Embedded)
Internal Drive Cage at Port 1I, Box 1, OK
Internal Drive Cage at Port 2I, Box 0, OK
Port Name: 1I (Mixed)
Port Name: 2I (Mixed)
Array A (Solid State SAS, Unused Space: 0 MB)
logicaldrive 1 (447.10 GB, RAID 1, OK)
physicaldrive 1I:1:1 (port 1I:box 1:bay 1, SAS SSD, 480 GB, OK)
physicaldrive 1I:1:2 (port 1I:box 1:bay 2, SAS SSD, 480 GB, OK)
SEP (Vendor ID HPE, Model Smart Adapter) 379 (Port: Unknown)
I have to figure out the Array name in order to delete it by searching for the matching disk info which I get as input from the user. For example, if the disk input is 1I:1:1 then I have to search for this string in the output of the above command. Since this disk is available and matching, I have to extract the Array name (here it is 'A') and once I get this Array parameter then I can go ahead delete this existing RAID configuration.
ssacli ctrl slot=0 show config | grep -B 4 '1I:1:1' | grep Array | awk 'print $2'
The problem with the above command is,
value 4 in the grep -B cannot be always constant as the matching disk may come first, second or third or so on under an Array in the output.
there may be multiple RAID array configurations available in the output, so there may be Array A, B, C etc., I have to find and retrieve the nearest "Array" string that matches my input disk
shell-script text-processing raid
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Below is the HP ssacli command to see configured hardware RAID details:
ssacli ctrl slot=0 show config
and its output is as below:
HPE Smart Array P408i-a SR Gen10 in Slot 0 (Embedded)
Internal Drive Cage at Port 1I, Box 1, OK
Internal Drive Cage at Port 2I, Box 0, OK
Port Name: 1I (Mixed)
Port Name: 2I (Mixed)
Array A (Solid State SAS, Unused Space: 0 MB)
logicaldrive 1 (447.10 GB, RAID 1, OK)
physicaldrive 1I:1:1 (port 1I:box 1:bay 1, SAS SSD, 480 GB, OK)
physicaldrive 1I:1:2 (port 1I:box 1:bay 2, SAS SSD, 480 GB, OK)
SEP (Vendor ID HPE, Model Smart Adapter) 379 (Port: Unknown)
I have to figure out the Array name in order to delete it by searching for the matching disk info which I get as input from the user. For example, if the disk input is 1I:1:1 then I have to search for this string in the output of the above command. Since this disk is available and matching, I have to extract the Array name (here it is 'A') and once I get this Array parameter then I can go ahead delete this existing RAID configuration.
ssacli ctrl slot=0 show config | grep -B 4 '1I:1:1' | grep Array | awk 'print $2'
The problem with the above command is,
value 4 in the grep -B cannot be always constant as the matching disk may come first, second or third or so on under an Array in the output.
there may be multiple RAID array configurations available in the output, so there may be Array A, B, C etc., I have to find and retrieve the nearest "Array" string that matches my input disk
shell-script text-processing raid
Below is the HP ssacli command to see configured hardware RAID details:
ssacli ctrl slot=0 show config
and its output is as below:
HPE Smart Array P408i-a SR Gen10 in Slot 0 (Embedded)
Internal Drive Cage at Port 1I, Box 1, OK
Internal Drive Cage at Port 2I, Box 0, OK
Port Name: 1I (Mixed)
Port Name: 2I (Mixed)
Array A (Solid State SAS, Unused Space: 0 MB)
logicaldrive 1 (447.10 GB, RAID 1, OK)
physicaldrive 1I:1:1 (port 1I:box 1:bay 1, SAS SSD, 480 GB, OK)
physicaldrive 1I:1:2 (port 1I:box 1:bay 2, SAS SSD, 480 GB, OK)
SEP (Vendor ID HPE, Model Smart Adapter) 379 (Port: Unknown)
I have to figure out the Array name in order to delete it by searching for the matching disk info which I get as input from the user. For example, if the disk input is 1I:1:1 then I have to search for this string in the output of the above command. Since this disk is available and matching, I have to extract the Array name (here it is 'A') and once I get this Array parameter then I can go ahead delete this existing RAID configuration.
ssacli ctrl slot=0 show config | grep -B 4 '1I:1:1' | grep Array | awk 'print $2'
The problem with the above command is,
value 4 in the grep -B cannot be always constant as the matching disk may come first, second or third or so on under an Array in the output.
there may be multiple RAID array configurations available in the output, so there may be Array A, B, C etc., I have to find and retrieve the nearest "Array" string that matches my input disk
shell-script text-processing raid
edited Jun 27 at 15:24
SivaPrasath
3,88611737
3,88611737
asked Jun 27 at 14:15
Ibrahim Quraish
1419
1419
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
The following perl oneliner reads the file line by line, recording the last array until it meets the line with the physical drive '1I:1:1':
ssacli ctrl slot=0 show config | perl -ne 'if ($_ =~ /Array (.)/) $array = $1; elsif ($_ =~ /physicaldrive 1I:1:1/) print $array; exit; '
Got from other forum as:awk -v disk='1I:1:1' '/^[[:space:]]*Array/ array=$2 $0 ~ disk print array; exit'
â Ibrahim Quraish
Jun 28 at 14:33
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
The following perl oneliner reads the file line by line, recording the last array until it meets the line with the physical drive '1I:1:1':
ssacli ctrl slot=0 show config | perl -ne 'if ($_ =~ /Array (.)/) $array = $1; elsif ($_ =~ /physicaldrive 1I:1:1/) print $array; exit; '
Got from other forum as:awk -v disk='1I:1:1' '/^[[:space:]]*Array/ array=$2 $0 ~ disk print array; exit'
â Ibrahim Quraish
Jun 28 at 14:33
add a comment |Â
up vote
1
down vote
accepted
The following perl oneliner reads the file line by line, recording the last array until it meets the line with the physical drive '1I:1:1':
ssacli ctrl slot=0 show config | perl -ne 'if ($_ =~ /Array (.)/) $array = $1; elsif ($_ =~ /physicaldrive 1I:1:1/) print $array; exit; '
Got from other forum as:awk -v disk='1I:1:1' '/^[[:space:]]*Array/ array=$2 $0 ~ disk print array; exit'
â Ibrahim Quraish
Jun 28 at 14:33
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
The following perl oneliner reads the file line by line, recording the last array until it meets the line with the physical drive '1I:1:1':
ssacli ctrl slot=0 show config | perl -ne 'if ($_ =~ /Array (.)/) $array = $1; elsif ($_ =~ /physicaldrive 1I:1:1/) print $array; exit; '
The following perl oneliner reads the file line by line, recording the last array until it meets the line with the physical drive '1I:1:1':
ssacli ctrl slot=0 show config | perl -ne 'if ($_ =~ /Array (.)/) $array = $1; elsif ($_ =~ /physicaldrive 1I:1:1/) print $array; exit; '
answered Jun 27 at 14:51
lgeorget
8,50122448
8,50122448
Got from other forum as:awk -v disk='1I:1:1' '/^[[:space:]]*Array/ array=$2 $0 ~ disk print array; exit'
â Ibrahim Quraish
Jun 28 at 14:33
add a comment |Â
Got from other forum as:awk -v disk='1I:1:1' '/^[[:space:]]*Array/ array=$2 $0 ~ disk print array; exit'
â Ibrahim Quraish
Jun 28 at 14:33
Got from other forum as:
awk -v disk='1I:1:1' '/^[[:space:]]*Array/ array=$2 $0 ~ disk print array; exit'
â Ibrahim Quraish
Jun 28 at 14:33
Got from other forum as:
awk -v disk='1I:1:1' '/^[[:space:]]*Array/ array=$2 $0 ~ disk print array; exit'
â Ibrahim Quraish
Jun 28 at 14:33
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f452233%2fextract-a-string-that-is-located-above-and-nearest-to-the-matching-pattern-in-a%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password