要获取getsnapshot for tables on dbname输出的表信息中一个表的信息,我们需要匹配到两行,然后输出一段这种就不是之前简单的列输出了,这个要怎么办呢?
[db2inst1@db22 ~]$ db2 get snapshot for tables on kilo
Table Snapshot
First database connect timestamp = 09/22/2017 10:41:19.323227
Last reset timestamp =
Snapshot timestamp = 09/25/2017 09:21:52.828200
Database name = KILO
Database path = /home/db2inst1/db2inst1/NODE0000/SQL00002/MEMBER0000/
Input database alias = KILO
Number of accessed tables = 12
Table List
Table Schema = SYSIBM
Table Name = SYSTABLES
Table Type = Catalog
Data Object Pages = 90
Index Object Pages = 50
LOB Object pages = 1088
Rows Read = Not Collected
Rows Written = 55
Overflows = 36
Page Reorgs = 0
Table Schema = SYSIBM
Table Name = SYSCOLUMNS
Table Type = Catalog
Data Object Pages = 423
Index Object Pages = 193
LOB Object pages = 1
Rows Read = Not Collected
Rows Written = 18
Overflows = 0
Page Reorgs = 4
Table Schema = SYSIBM
Table Name = SYSINDEXES
Table Type = Catalog
Data Object Pages = 43
Index Object Pages = 25
LOB Object pages = 1
Rows Read = Not Collected
Rows Written = 60
Overflows = 35
Page Reorgs = 1
Table Schema = SYSTOOLS
Table Name = HMON_ATM_INFO
Table Type = User
Data Object Pages = 15
Index Object Pages = 6
Rows Read = Not Collected
Rows Written = 1799
Overflows = 6243
Page Reorgs = 1
Table Schema = SYSIBM
Table Name = SYSINDEXCOLUSE
Table Type = Catalog
Data Object Pages = 18
Index Object Pages = 23
LOB Object pages = 1
Rows Read = Not Collected
Rows Written = 1
Overflows = 0
Page Reorgs = 0
Table Schema = SYSIBM
Table Name = SYSDATAPARTITIONS
Table Type = Catalog
Data Object Pages = 8
Index Object Pages = 23
Rows Read = Not Collected
Rows Written = 5
Overflows = 0
Page Reorgs = 0
Table Schema = SYSIBM
Table Name = SYSPLAN
Table Type = Catalog
Data Object Pages = 47
Index Object Pages = 23
LOB Object pages = 448
Rows Read = Not Collected
Rows Written = 4
Overflows = 0
Page Reorgs = 0
Table Schema = SYSIBM
Table Name = SYSTABAUTH
Table Type = Catalog
Data Object Pages = 11
Index Object Pages = 30
Rows Read = Not Collected
Rows Written = 1
Overflows = 0
Page Reorgs = 0
Table Schema = SYSIBM
Table Name = SYSINDEXAUTH
Table Type = Catalog
Data Object Pages = 1
Index Object Pages = 10
Rows Read = Not Collected
Rows Written = 1
Overflows = 0
Page Reorgs = 0
Table Schema = SYSIBM
Table Name = SYSCOLDIST
Table Type = Catalog
Data Object Pages = 581
Index Object Pages = 627
Rows Read = Not Collected
Rows Written = 1980
Overflows = 0
Page Reorgs = 17
Table Schema = SYSIBM
Table Name = SYSUSERAUTH
Table Type = Catalog
Data Object Pages = 11
Index Object Pages = 16
LOB Object pages = 1
Rows Read = Not Collected
Rows Written = 1
Overflows = 0
Page Reorgs = 0
Table Schema = DB2INST1
Table Name = STUDENT
Table Type = User
Data Object Pages = 60
Index Object Pages = 34
Rows Read = Not Collected
Rows Written = 5283
Overflows = 0
Page Reorgs = 119
Table Reorg Information:
Reorg Type =
Reclustering
Inplace Table Reorg
Allow Write Access
Reorg Index = 1
Reorg Tablespace = 2
Start Time = 09/22/2017 14:19:56.266280
Reorg Phase =
Max Phase =
Phase Start Time =
Status = Completed
Current Counter = 0
Max Counter = 0
Completion = 0
End Time = 09/22/2017 14:19:57.358522
目标:匹配表 db2inst1.student,输出
Table Schema = DB2INST1
Table Name = STUDENT
这一段内容。
首先百度一下,然后看到一些有相似之处的案例先研究一下:
[db2inst1@db22 ~]$ db2 get snapshot for tables on kilo | sed -n '/^ Table Schema[ ]* = DB2INST1/N;x;/STUDENT/p'
Table Schema = DB2INST1
Table Name = STUDENT
[db2inst1@db22 ~]$ db2 get snapshot for tables on kilo | sed -n '/^ Table Schema[ ]* = DB2INST1/N;x;/STUDENT/{:a;N;/\n$/!{$!ba};p}'
Table Schema = DB2INST1
Table Name = STUDENT
Data Object Pages = 60
Index Object Pages = 34
Rows Read = Not Collected
Rows Written = 5283
Overflows = 0
Page Reorgs = 119
Table Reorg Information:
Reorg Type =
Reclustering
Inplace Table Reorg
Allow Write Access
Reorg Index = 1
Reorg Tablespace = 2
Start Time = 09/22/2017 14:19:56.266280
Reorg Phase =
Max Phase =
Phase Start Time =
Status = Completed
Current Counter = 0
Max Counter = 0
Completion = 0
End Time = 09/22/2017 14:19:57.358522
[db2inst1@db22 ~]$ she='DB2INST1'
[db2inst1@db22 ~]$ tb='STUDENT'
[db2inst1@db22 ~]$ db2 get snapshot for tables on kilo | sed -n '/^ Table Schema[ ]* = '"${she}"'/N;x;/Table Name[ ]*= '"${tb}"'/{:a;N;/\n$/!{$!ba};p}'
Table Schema = DB2INST1
Table Name = STUDENT
Data Object Pages = 60
Index Object Pages = 34
Rows Read = Not Collected
Rows Written = 5283
Overflows = 0
Page Reorgs = 119
Table Reorg Information:
Reorg Type =
Reclustering
Inplace Table Reorg
Allow Write Access
Reorg Index = 1
Reorg Tablespace = 2
Start Time = 09/22/2017 14:19:56.266280
Reorg Phase =
Max Phase =
Phase Start Time =
Status = Completed
Current Counter = 0
Max Counter = 0
Completion = 0
End Time = 09/22/2017 14:19:57.358522
[db2inst1@db22 ~]$ db2 get snapshot for tables on kilo | sed -n '/^ Table Schema[ ]*= DB2INST1/N;x;/Table Name[ ]*= STUDENT/{:a;N;/Table Reorg Information/!{$!ba}};x;/Table Reorg Information/{:a;N;/\n$/!{$!ba};p;}'
Table Reorg Information:
Reorg Type =
Reclustering
Table Reorg
Allow Read Access
Recluster Via Table Scan
Reorg Data Only
Reorg Index = 1
Reorg Tablespace = 2
Start Time = 09/28/2017 10:33:56.488234
Reorg Phase = 4 - Index Recreate
Max Phase = 4
Phase Start Time = 09/28/2017 10:33:57.463816
Status = Completed
Current Counter = 0
Max Counter = 0
Completion = 0
End Time = 09/28/2017 10:33:58.431537
命令的意义及解释参阅上一篇博文。
$!ba :末行不跳转至a,其他都跳转至a