Help with awk to extract additional info


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with awk to extract additional info
# 1  
Old 04-03-2018
Help with awk to extract additional info

Hi

I use multipath linux command to get LUNs info and find out if any failed.

Code:
#  multipath -ll >/tmp/mpfail
#  cat /tmp/mpfail
multipath.conf line 109, invalid keyword: user_friendly_names
multipath.conf line 153, invalid keyword: user_friendly_names
multipath.conf line 193, invalid keyword: user_friendly_names
multipath.conf line 225, invalid keyword: user_friendly_names
multipath.conf line 255, invalid keyword: user_friendly_names
multipath.conf line 293, invalid keyword: rr_nim_io
multipath.conf line 295, invalid keyword: user_friendly_names
multipath.conf line 315, invalid keyword: user_friendly_names
LUN08 (3600507680180856b1800000000000680) dm-12 IBM,2145
[size=500G][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=200][active]
 \_ 3:0:10:7 sdan 66:112 [active][ready]
 \_ 3:0:11:7 sdav 66:240 [active][ready]
 \_ 1:0:10:7 sdh  8:112  [active][ready]
 \_ 1:0:13:7 sdp  8:240  [active][ready]
\_ round-robin 0 [prio=40][enabled]
 \_ 1:0:15:7 sdaf 65:240 [active][ready]
 \_ 3:0:13:7 sdbd 67:112 [active][ready]
 \_ 3:0:15:7 sdbl 67:240 [active][ready]
 \_ 1:0:14:7 sdx  65:112 [active][ready]
LUN07 (3600507680180856b1800000000000679) dm-13 IBM,2145
[size=500G][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=200][active]
 \_ 3:0:13:0 sdaw 67:0   [active][ready]
 \_ 3:0:15:0 sdbe 67:128 [active][ready]
 \_ 1:0:14:0 sdq  65:0   [active][ready]
 \_ 1:0:15:0 sdy  65:128 [active][ready]
\_ round-robin 0 [prio=40][enabled]
 \_ 3:0:10:0 sdag 66:0   [active][ready]
 \_ 3:0:11:0 sdao 66:128 [active][ready]
 \_ 1:0:10:0 sda  8:0    [active][ready]
 \_ 1:0:13:0 sdi  8:128  [active][ready]
LUN06 (3600507680180856b180000000000067f) dm-11 IBM,2145
[size=500G][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=200][enabled]
 \_ 1:0:15:6 sdae 65:224 [failed][ready]
 \_ 3:0:13:6 sdbc 67:96  [failed][ready]
 \_ 3:0:15:6 sdbk 67:224 [failed][ready]
 \_ 1:0:14:6 sdw  65:96  [failed][ready]
\_ round-robin 0 [prio=40][enabled]
 \_ 3:0:10:6 sdam 66:96  [failed][ready]
 \_ 3:0:11:6 sdau 66:224 [failed][ready]
 \_ 1:0:10:6 sdg  8:96   [failed][ready]
 \_ 1:0:13:6 sdo  8:224  [failed][ready]
LUN05 (3600507680180856b180000000000067e) dm-10 IBM,2145
[size=500G][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=200][active]
 \_ 3:0:10:5 sdal 66:80  [active][ready]
 \_ 3:0:11:5 sdat 66:208 [active][ready]
 \_ 1:0:10:5 sdf  8:80   [active][ready]
 \_ 1:0:13:5 sdn  8:208  [active][ready]
\_ round-robin 0 [prio=40][enabled]
 \_ 1:0:15:5 sdad 65:208 [active][ready]
 \_ 3:0:13:5 sdbb 67:80  [active][ready]
 \_ 3:0:15:5 sdbj 67:208 [active][ready]
 \_ 1:0:14:5 sdv  65:80  [active][ready]
LUN04 (3600507680180856b180000000000067d) dm-9 IBM,2145
[size=500G][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=200][active]
 \_ 1:0:15:4 sdac 65:192 [active][ready]
 \_ 3:0:13:4 sdba 67:64  [active][ready]
 \_ 3:0:15:4 sdbi 67:192 [active][ready]
 \_ 1:0:14:4 sdu  65:64  [active][ready]
\_ round-robin 0 [prio=40][enabled]
 \_ 3:0:10:4 sdak 66:64  [active][ready]
 \_ 3:0:11:4 sdas 66:192 [active][ready]
 \_ 1:0:10:4 sde  8:64   [active][ready]
 \_ 1:0:13:4 sdm  8:192  [active][ready]
LUN03 (3600507680180856b180000000000067c) dm-8 IBM,2145
[size=500G][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=200][active]
 \_ 3:0:10:3 sdaj 66:48  [active][ready]
 \_ 3:0:11:3 sdar 66:176 [active][ready]
 \_ 1:0:10:3 sdd  8:48   [active][ready]
 \_ 1:0:13:3 sdl  8:176  [active][ready]
\_ round-robin 0 [prio=40][enabled]
 \_ 1:0:15:3 sdab 65:176 [active][ready]
 \_ 3:0:13:3 sdaz 67:48  [active][ready]
 \_ 3:0:15:3 sdbh 67:176 [active][ready]
 \_ 1:0:14:3 sdt  65:48  [active][ready]
LUN02 (3600507680180856b180000000000067b) dm-7 IBM,2145
[size=500G][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=200][active]
 \_ 1:0:15:2 sdaa 65:160 [active][ready]
 \_ 3:0:13:2 sday 67:32  [active][ready]
 \_ 3:0:15:2 sdbg 67:160 [active][ready]
 \_ 1:0:14:2 sds  65:32  [active][ready]
\_ round-robin 0 [prio=40][enabled]
 \_ 3:0:10:2 sdai 66:32  [active][ready]
 \_ 3:0:11:2 sdaq 66:160 [active][ready]
 \_ 1:0:10:2 sdc  8:32   [active][ready]
 \_ 1:0:13:2 sdk  8:160  [active][ready]
LUN01 (3600507680180856b180000000000067a) dm-14 IBM,2145
[size=500G][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=200][active]
 \_ 3:0:10:1 sdah 66:16  [active][ready]
 \_ 3:0:11:1 sdap 66:144 [active][ready]
 \_ 1:0:10:1 sdb  8:16   [active][ready]
 \_ 1:0:13:1 sdj  8:144  [active][ready]
\_ round-robin 0 [prio=40][enabled]
 \_ 3:0:13:1 sdax 67:16  [active][ready]
 \_ 3:0:15:1 sdbf 67:144 [active][ready]
 \_ 1:0:14:1 sdr  65:16  [active][ready]
 \_ 1:0:15:1 sdz  65:144 [active][ready]

#

As the above output has few failed lines I need both lines containing failed and also its LUN number (the line starts with LUN)

I tried below but no luck -

Code:
multipath -ll >/tmp/mpfail
awk '/^LUN/ { _ = $0 }
/failed/ && { print _; }
'  /tmp/mpfail

It would be fantastic if I could entire para/stanza of that LUN which has failed items like below:

Code:
LUN06 (3600507680180856b180000000000067f) dm-11 IBM,2145
[size=500G][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=200][enabled]
 \_ 1:0:15:6 sdae 65:224 [failed][ready]
 \_ 3:0:13:6 sdbc 67:96  [failed][ready]
 \_ 3:0:15:6 sdbk 67:224 [failed][ready]
 \_ 1:0:14:6 sdw  65:96  [failed][ready]
\_ round-robin 0 [prio=40][enabled]
 \_ 3:0:10:6 sdam 66:96  [failed][ready]
 \_ 3:0:11:6 sdau 66:224 [failed][ready]
 \_ 1:0:10:6 sdg  8:96   [failed][ready]
 \_ 1:0:13:6 sdo  8:224  [failed][ready]

Please advise, thanks!!
# 2  
Old 04-03-2018
Hello prvnrk,

Could you please try following and let me know if this helps you.
Code:
awk '/^LUN/{flag=1;if(flag && non_flag){print val};val=flag=non_flag=""} /failed/{non_flag=1} {val=val?val ORS $0:$0}'  Input_file

OR

Code:
Your_command | awk '/^LUN/{flag=1;if(flag && non_flag){print val};val=flag=non_flag=""} /failed/{non_flag=1} {val=val?val ORS $0:$0}'

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 04-03-2018
Try also
Code:
awk '
/^LUN/          {LUN = $0
                 next
                }
/round-robin/   {RRO = $0
                 next
                }
/failed/        {if (LUN) print LUN
                 if (RRO) print RRO
                 LUN = RRO = ""
                 print
                }
' /tmp/mpfail

This User Gave Thanks to RudiC For This Post:
# 4  
Old 04-03-2018
Thank you RavinderSingh13 & RudiC

Both solutions worked! Smilie

Best regards,
# 5  
Old 04-03-2018
Below is a slight change to RudiC's solution to also print the line following the LUN:

Code:
awk '
/^LUN/          {LUN = $0 
                 getline
                 LUN=LUN "\n" $0 
                }
/round-robin/   {RRO = $0 }
/failed/        {if (LUN) print LUN
                 if (RRO) print RRO
                 LUN = RRO = ""
                 print
                }
'  /tmp/mpfail

Output:

Code:
LUN06 (3600507680180856b180000000000067f) dm-11 IBM,2145
[size=500G][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=200][enabled]
 \_ 1:0:15:6 sdae 65:224 [failed][ready]
 \_ 3:0:13:6 sdbc 67:96  [failed][ready]
 \_ 3:0:15:6 sdbk 67:224 [failed][ready]
 \_ 1:0:14:6 sdw  65:96  [failed][ready]
\_ round-robin 0 [prio=40][enabled]
 \_ 3:0:10:6 sdam 66:96  [failed][ready]
 \_ 3:0:11:6 sdau 66:224 [failed][ready]
 \_ 1:0:10:6 sdg  8:96   [failed][ready]
 \_ 1:0:13:6 sdo  8:224  [failed][ready]

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to extract multiple values from file and add two additional fields

In the attached file I am trying to use awk to extract multiple values and create the tab-delimited desired output. In the output R_Index is a the sequential # and Pre_Enrichment is defaulted to .. I can extract from the values to the side of the keywords, but most are above and I can not... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

How to extract info from pings.?

Hi guys, new to this forum. I am currently trying to extract the times from pinging a domain and list the top 3 and then also do the opposite i.e. list the bottom 3. so if I had this as a ping result (the bold part is what I want): 64 bytes from 193.120.166.90: icmp_seq=10 ttl=128 time=34.8... (5 Replies)
Discussion started by: acoding
5 Replies

3. Shell Programming and Scripting

Extract info and do algebra on it by sed or awk

Hello everyone, I need to extract some information from a csv file and further need to do some algebraic calculations on those information and then to throw the result in a new file. Here is a sample from my data.csv file; Col1,Col2,Col3,Col4,Col5,Col6,Col7... (19 Replies)
Discussion started by: hayreter
19 Replies

4. Forum Support Area for Unregistered Users & Account Problems

Sign in issues -- additional info as requested

User name: Michael Mullig <removed email addresses> (1 Reply)
Discussion started by: Mike Mullig
1 Replies

5. Shell Programming and Scripting

Create a file from ls -l command and append additional info to results

I need to be able to take the results from ls -l command and modify the output as follows: I will run ls -l *.mak My results will be aa.mak bb.mak cc.mak I then need to take those results and create a file that has the following info: dsjj/ubin/aa dsjj/ubin/bb dsjj/ubin/cc ... (3 Replies)
Discussion started by: jclanc8
3 Replies

6. Programming

Insert value from field1 to field2 with additional info

Need help - hopefully I explain it correctly I have a table in mysql database with multiple fields. 2 of the fields are called id and id_link id id_link 93 http://test_server/testpage.cgi?93 95 96 97 98 I need to find the correct sql to update all of the id_link... (2 Replies)
Discussion started by: frustrated1
2 Replies

7. Shell Programming and Scripting

Using AWK BEGIN to extract file header info into variables

Hi Folks, I've searched for this for quite a while, but can't find any solution - hope someone can help. I have various files with standard headers. eg. <HEADER> IP: 1.2.3.4 Username: Joe Time: 12:00:00 Date: 23/05/2010 </HEADER> This is a test and this part can be any size... (6 Replies)
Discussion started by: damoske
6 Replies

8. Shell Programming and Scripting

how to extract info from a file using awk

Dear all I have a file call interfaces.txt Filename: interfaces.txt How can I extract the information at below? ABC_DB_001 hostname1 20901 ABC_DB_002 hostname2 20903 ABC_DB_003 hostname3 20905 Currently I am using a very stupid method grep ^ABC interfaces.txt > name.txt grep... (3 Replies)
Discussion started by: on9west
3 Replies

9. AIX

Extract info

Anyone have a better idea to automate extraction of info like ... "uname" "ifconfig" "ps efl" "netstat -ao" etc. from several hundred aix, solaris, red hat boxes? without logging into each box and manually performing these tasks and dumping them to individual files? thanks for any input (1 Reply)
Discussion started by: chm0dvii
1 Replies

10. UNIX for Dummies Questions & Answers

using cut to extract info

a simple question, how can i use cut (after using grep) to extract the last four digits on a line. so say i had a string http://blabla:9020, how would I extract the port?? -Fez (4 Replies)
Discussion started by: hafhaq
4 Replies
Login or Register to Ask a Question