签到成功

知道了

CNDBA社区CNDBA社区

Python获取某字符串在文本中的位置

2022-02-10 21:12 1392 0 原创 Python
作者: hbhe0316

1.获取DB2:db2 -d testdb -tab信息http://www.cndba.cn/hbhe0316/article/106640http://www.cndba.cn/hbhe0316/article/106640

Database Member 0 -- Database SOURCEDB -- Active -- Up 0 days 00:00:15 -- Date 2022-02-10-20.05.48.065532

Tablespace Configuration:
Address            Id    Type Content PageSz ExtentSz Auto Prefetch BufID BufIDDisk FSC NumCntrs MaxStripe  LastConsecPg RSE  Name
0x00002AAB116AC540 0     DMS  Regular 8192   4        Yes  4        1     1         Def 1        0          3            Yes  SYSCATSPACE
0x00002AAB116B9900 1     SMS  SysTmp  8192   32       Yes  32       1     1         On  1        0          31           No   TEMPSPACE1
0x00002AAB116C6CC0 2     DMS  Large   8192   32       Yes  32       1     1         Def 1        0          31           Yes  USERSPACE1
0x00002AAB116D4080 3     DMS  Large   8192   4        Yes  4        1     1         Def 1        0          3            Yes  SYSTOOLSPACE
0x00002AAB116E1440 4     SMS  UsrTmp  8192   32       Yes  32       1     1         On  1        0          31           No   ASNADMINIFSPACE
0x00002AAB31BE0080 5     DMS  Large   8192   32       Yes  32       1     1         Def 1        0          31           Yes  QCASN

Tablespace Statistics:
Address            Id    TotalPgs   UsablePgs  UsedPgs    PndFreePgs FreePgs    HWM        Max HWM    State      MinRecTime NQuiescers PathsDropped TrackmodState    
0x00002AAB116AC540 0     20480      20476      16512      0          3964       16512      16512      0x00000000 0          0          No           Dirty            
0x00002AAB116B9900 1     1          1          1          0          0          -          -          0x00000000 0          0          No           Dirty            
0x00002AAB116C6CC0 2     4096       4064       160        0          3904       160        160        0x00000000 1633519810 0          No           Dirty            
0x00002AAB116D4080 3     4096       4092       108        0          3984       108        108        0x00000000 1633519398 0          No           Dirty            
0x00002AAB116E1440 4     1          1          1          0          0          -          -          0x00000000 1633519566 0          No           Clean            
0x00002AAB31BE0080 5     4096       4064       2400       0          1664       2400       2400       0x00000000 1633519573 0          No           Dirty            

Tablespace Autoresize Statistics:
Address            Id    AS  AR  InitSize             IncSize              IIP MaxSize              LastResize                 LRF
0x00002AAB116AC540 0     Yes Yes 33554432             -1                   No  None                 None                       No  
0x00002AAB116B9900 1     Yes No  0                    0                    No  0                    None                       No  
0x00002AAB116C6CC0 2     Yes Yes 33554432             -1                   No  None                 None                       No  
0x00002AAB116D4080 3     Yes Yes 33554432             -1                   No  None                 None                       No  
0x00002AAB116E1440 4     Yes No  0                    0                    No  0                    None                       No  
0x00002AAB31BE0080 5     Yes Yes 33554432             -1                   No  None                 None                       No  

Tablespace Storage Statistics:
Address            Id    DataTag  Rebalance SGID  SourceSGID
0x00002AAB116AC540 0     0        No        0     -                    
0x00002AAB116B9900 1     0        No        0     -                    
0x00002AAB116C6CC0 2     -1       No        0     -                    
0x00002AAB116D4080 3     -1       No        0     -                    
0x00002AAB116E1440 4     0        No        0     -                    
0x00002AAB31BE0080 5     -1       No        0     -                    

Containers:
Address            TspId ContainNum Type    TotalPgs   UseablePgs PathID     StripeSet  Container 
0x00002AAB116A58C0 0     0          File    20480      20476      0          0          /db2data/db2inst1/NODE0000/SOURCEDB/T0000000/C0000000.CAT
0x00002AAB1163DB60 1     0          Path    1          1          0          0          /db2data/db2inst1/NODE0000/SOURCEDB/T0000001/C0000000.TMP
0x00002AAB11633B40 2     0          File    4096       4064       0          0          /db2data/db2inst1/NODE0000/SOURCEDB/T0000002/C0000000.LRG
0x00002AAB1163E360 3     0          File    4096       4092       0          0          /db2data/db2inst1/NODE0000/SOURCEDB/T0000003/C0000000.LRG
0x00002AAB1163EA40 4     0          Path    1          1          0          0          /db2data/db2inst1/NODE0000/SOURCEDB/T0000004/C0000000.UTM
0x00002AAB11622240 5     0          File    4096       4064       0          0          /db2data/db2inst1/NODE0000/SOURCEDB/T0000005/C0000000.LRG

2.使用Python获取某字符串位置http://www.cndba.cn/hbhe0316/article/106640http://www.cndba.cn/hbhe0316/article/106640http://www.cndba.cn/hbhe0316/article/106640

http://www.cndba.cn/hbhe0316/article/106640
http://www.cndba.cn/hbhe0316/article/106640
http://www.cndba.cn/hbhe0316/article/106640

str_start = "Tablespace Statistics:"
str_end = "Tablespace Autoresize Statistics:"

def fileTest(strVal):
    lineNum = 0
    msg = "There is no result"
    with open(r"G:/python/db2pd_sourcedb_tab.txt", 'r') as file:
        for line in file.readlines():
            lineNum = lineNum + 1
            if strVal in line.strip():
                msg = "'%s' string in line %d" % (strVal, lineNum)
                break
    print(msg)

def main():
    fileTest(str_start)
    fileTest(str_end)

if __name__ == "__main__":
    main()

3.执行效果
http://www.cndba.cn/hbhe0316/article/106640http://www.cndba.cn/hbhe0316/article/106640

版权声明:本文为博主原创文章,未经博主允许不得转载。

Python

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
hbhe0316

hbhe0316

关注

1.只有承认无知,才能装下新的东西; 2.进步来自一点点滴滴的积累; 3.广博让你更优秀,而专业让你无法替代; 4.挫折和失败能够转换为一种财富。

  • 889
    原创
  • 1
    翻译
  • 13
    转载
  • 24
    评论
  • 访问:1038889次
  • 积分:1523
  • 等级:核心会员
  • 排名:第6名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ