Reputation: 4557
The string looks as follows:
Event Id: 971
Time : Fri Mar 28 03:50:03 2014
Type : INFO
User : ehwe
Message :
Oracle_Connector_1,0: Number of rows fetched on the current node: 0.
I need to get the sub string that follows the Message :. So I in this case I need this Oracle_Connector_1,0: Number of rows fetched on the current node: 0.
I've tried using b=${a%'Message :'*}
format but that didn't help.
Little help, please?
Update:
Some log entries might look like the next one:
Event Id: 970
Time : Fri Mar 28 03:50:03 2014
Type : FATAL
User : ehwe
Message :
Oracle_Connector_1,0: [IIS-CONN-ORA-001003] The OCI function OCIStmtExecute returned status -1. Error code: 6,550, Error message: ORA-06550: line 2, column 14:
PLS-00201: identifier 'IT' must be declared
ORA-06550: line 2, column 14:
PL/SQL: Item ignored
ORA-06550: line 5, column 5:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 5, column 5:
PL/SQL: Statement ignored
ORA-06550: line 8, column 26:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 8, column 7:
PL/SQL: Statement ignored. (CC_OraStatement::executePlSql, file CC_OraStatement.cpp, line 2,746)
Upvotes: 2
Views: 8800
Reputation: 289555
You can use this:
awk 'f; /Message/ {f=1}' file
f
is set, condition is true so awk
prints the line.Message
appears, the flag f
is set to 1.If you want to print exactly the line after Message
occurs, you can do:
$ awk 'f {print; exit} /Message/ {f=1}' file
Oracle_Connector_1,0: [IIS-CONN-ORA-001003] The OCI function OCIStmtExecute returned status -1. Error code: 6,550, Error message: ORA-06550: line 2, column 14:
It is the same as above, just that after printing for the first time, it stops reading the file and exits
.
To use a variable as input instead of a file, use:
awk 'f {print; exit} /Message/ {f=1}' <<< "$var"
See an example:
$ echo "$var"
hello
how are you
$ awk '1' <<< "$var"
hello
how are you
Upvotes: 2
Reputation: 8446
I expect ${a%'Message :'*}
to return the first four lines. If $a
contains the entire message above, reverse the match:
a="Event Id: 971
Time : Fri Mar 28 03:50:03 2014
Type : INFO
User : ehwe
Message :
Oracle_Connector_1,0: Number of rows fetched on the current node: 0."
echo "${a#*Message :[$IFS]}"
Outputs:
Oracle_Connector_1,0: Number of rows fetched on the current node: 0.
Note:
Using [$IFS]
because I'm too lazy to figure out an explicit match with the newline character. That can be improved.
Tested in bash
and ksh93
Upvotes: 1
Reputation: 182
grep -A1 Message | tail -1
should do the trick. -A1 tells grep the write one more line to the output (after 1) when a match is found.
Upvotes: 1