Grep Database from db2diag.log string

0

I want to get the Database String from Part EDUNAME: db2agent (PRD)

My first try does not work ;-)

sed 's/.*EDUNAME: .* (//' | sed 's/).*FUNCTION.*//

Output:

2016-02-16-15.29.08.030467+060 I11738607E972         LEVEL: Error PID 
: 28641                TID : 46912874997504  PROC : db2sysc 0
INSTANCE: db2inst               NODE : 000            DB   : PRD
APPHDL  : 0-25656              APPID: *LOCAL.db2t08.160216144150
AUTHID  : DB2ISNT              HOSTNAME: UNIX1 
EDUID   : 44342                EDUNAME: db2agent (PRD) 0 
FUNCTION: DB2 UDB, relation data serv,
sqlrr_rds_common_post, probe:1700 MESSAGE : Severe TERMINATE err at
nest lvl 1, in SQL from rtn
          SYSPROC.SYSINSTALLOBJECTS: DATA #1 : SQLCA, PD_DB2_TYPE_SQLCA, 136 bytes  sqlcaid : SQLCA     sqlcabc: 136  
sqlcode: -1224   sqlerrml: 0  sqlerrmc:  sqlerrp : SQLRRRCP  sqlerrd :
(1) 0x80040003      (2) 0x00000003      (3) 0x00000000
           (4) 0x00000000      (5) 0xFFFFFE0C      (6) 0x00000000  sqlwarn : (1)      (2)      (3)      (4)        (5)       (6)
           (7)      (8)      (9)      (10)        (11)  sqlstate: 55032

Can anybody help me?

sed
grep
asked on Stack Overflow Feb 16, 2016 by Michael • edited Feb 17, 2016 by Michael

2 Answers

1

If you have GNU grep, you can do the following:

 $ grep -Po ' EDUNAME: db2agent \(\K[^)]+' file
 PRD
  • -P actives support for PCREs (Perl-Compatible Regular Expressions)
  • -o only outputs what the regex matched.
  • \K inside the regex drops everything matched so far.
  • [^)]+ then captures everything before the closing ).
answered on Stack Overflow Feb 17, 2016 by mklement0 • edited Feb 18, 2016 by mklement0
0
$ cat in
2011-01-10-12.10.13.923352-300 I74680A573 LEVEL: Warning
PID : 1234 TID : 100 PROC : db2sysc
INSTANCE: db2inst1 NODE : 000 DB : SAMPLE
APPHDL : 0-33648 APPID: 192.168.1.1.50234.11022217100
AUTHID : DB2INST1
EDUID : 608 EDUNAME: db2agent (SAMPLE) 0
FUNCTION: DB2 UDB, routine_infrastructure, sqlerMasterThreadReq,
probe:89
MESSAGE : FMP reported it could not create a new thread
DATA #1 : Hexdump, 4 bytes
0x000000020210F180 : 0000 0C05 ....

$ sed -n '/.* EDUNAME: \([^ ]*\).*/s//\1/p' in
db2agent

The -n switch to sed says to skip automatic printing. The regular expression captures a non-space sequence after EDUNAME:. If the regular expression matches, the s//\1/p reuses the prior regex, replaces the match with the first capture and prints the result.

Or maybe you want the next word:

$ sed -n '/.* EDUNAME: [^ ]* (\([^ ]*\)).*/s//\1/p' in                                                                                                     
SAMPLE
answered on Stack Overflow Feb 17, 2016 by dancancode

User contributions licensed under CC BY-SA 3.0