[20210507]如何實現.txt

lfree發表於2021-05-07

[20210507]如何實現.txt

--//前面的測試,連結:http://blog.itpub.net/267265/viewspace-2771267/ =>[20210507]dump library_cache.txt
--//如何寫簡單指令碼實現1個Bucket下,有2行^  LibraryHandle:的輸出呢? 把轉儲檔案複製出來,在家裡做一個嘗試.

C:\other> grep -E "^Bucket:|^  LibraryHandle:|^$" book_ora_12044_0003.trc >aa.txt

--//真心話,寫了一個多小時,程式碼如下:

C:\other>cat a1.awk
BEGIN {
line = 0
bucket = ""
library = ""
}

/^Bucket:/,/^$/ {
    if ($0 ~ /^Bucket:/) {
        line=0
        bucket=$0
    }

    if ($0 ~ /^  LibraryHandle:/ && line == 0 ) {
        line=NR
        library=$0
    }

    if ($0 ~ /^  LibraryHandle:/ && line != 0 ) {
        if ( line+1 == NR ) {
            printf "%s\n" ,bucket
            printf "%s\n" ,library
            printf "%s\n\n" ,$0
            line = 0
            bucket = ""
            library = ""
        }
    }
}

C:\other>awk -f a1.awk aa.txt | head -20
Bucket: #=2722 Mutex=0x80a8b8a8(0, 72, 0, 6)
  LibraryHandle:  Address=0x7d6449f8 Hash=ae0e0aa2 LockMode=0 PinMode=0 LoadLockMode=0 Status=VALD
  LibraryHandle:  Address=0x7c991c18 Hash=a8240aa2 LockMode=0 PinMode=0 LoadLockMode=0 Status=VALD

Bucket: #=3845 Mutex=0x80a96820(0, 71, 0, 6)
  LibraryHandle:  Address=0x7e252928 Hash=27660f05 LockMode=0 PinMode=0 LoadLockMode=0 Status=0
  LibraryHandle:  Address=0x7e04d730 Hash=a2e00f05 LockMode=0 PinMode=0 LoadLockMode=0 Status=VALD

Bucket: #=4143 Mutex=0x80a996b0(0, 59, 0, 6)
  LibraryHandle:  Address=0x7c9bc308 Hash=f0f0102f LockMode=0 PinMode=0 LoadLockMode=0 Status=0
  LibraryHandle:  Address=0x7bd3ca68 Hash=5b5e102f LockMode=0 PinMode=0 LoadLockMode=0 Status=0

Bucket: #=7663 Mutex=0x80abbcb0(0, 59, 0, 6)
  LibraryHandle:  Address=0x7d6aea60 Hash=61ae1def LockMode=0 PinMode=0 LoadLockMode=0 Status=VALD
  LibraryHandle:  Address=0x7c516960 Hash=eb7e1def LockMode=0 PinMode=0 LoadLockMode=0 Status=0

Bucket: #=8108 Mutex=0x80ac0238(0, 70, 0, 6)
  LibraryHandle:  Address=0x7bf0d468 Hash=c21a1fac LockMode=0 PinMode=0 LoadLockMode=0 Status=0
  LibraryHandle:  Address=0x7c11b0c8 Hash=aadc1fac LockMode=0 PinMode=0 LoadLockMode=0 Status=VALD

awk: a1.awk:22: (FILENAME=aa.txt FNR=5998) fatal: printf to "standard output" failed (Invalid argument)

C:\other>awk -f a1.awk aa.txt | grep "Bucket" |wc
     57     342    2691

--//與轉儲的下劃線看到的庫快取物件數量一致.
Library Cache Dump
SGA:0x80a6fea8 Flags=ac3
DebugContext:  DebugNameSpace=0 DebugType=0 DebugLevel=0x0
LIBRARY CACHE HASH TABLE: size=131072 count=3764
Buckets with more than 20 objects:
NONE
Hash Chain Size     Number of Buckets
---------------     -----------------
              0                127365
              1                  3650
              2                    57
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~              
              3                     0
              4                     0
              5                     0
              6                     0
              7                     0
              8                     0
              9                     0
             10                     0
             11                     0
             12                     0
             13                     0
             14                     0
             15                     0
             16                     0
             17                     0
             18                     0
             19                     0
             20                     0
            >20                     0

--//如果要寫指令碼實現1個Bucket下,有3行^  LibraryHandle:的輸出,程式碼還給重新寫.放棄,不擅長awk的指令碼語言.

--//那位知道更好的寫法..

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2771270/,如需轉載,請註明出處,否則將追究法律責任。

相關文章