LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   grep -w E (https://www.linuxquestions.org/questions/linux-general-1/grep-w-e-797568/)

dnaqvi 03-24-2010 11:17 AM

grep -w E
 
Hello All,

We are getting many messages in the log file.
There are many types of messages,
i.e. W for warning, E for error etc,

We wanted to grep errors contain only error type "E".
If I grep E it is greping all words which has letter E.

I trid to do below command but its getting repeating values.

grep -w E SystemOut.log | sort | uniq >> sysfinal2

Please help me for the write command.

thanks

slinx 03-24-2010 12:17 PM

You can replace
Code:

sort | uniq
with
Code:

sort -u
It would help if you posted examples of what you are getting with your command. Most likely you are seeing multiple lines for the same error, because the error text, or the timestamps, differ.

dnaqvi 03-24-2010 02:09 PM

grep -w E SystemOut.log | sort -u >> sysfinal2


I am getting repaeting values (only time stamps is different)

Here is one of the message:

[2/6/10 9:38:24:485 PST] 00000012 WSRdbXaResour E DSRA0302E: XAException occurred. Error code is: XA_RBOTHER (104). Exception is: <null>

[2/6/10 9:39:04:505 PST] 00000012 WSRdbXaResour E DSRA0302E: XAException occurred. Error code is: XA_RBOTHER (104). Exception is: <null>

thanks

blacky_5251 03-25-2010 05:10 PM

Try grepping for " E " instead of just "E" - i.e. space E space in quotes.

dnaqvi 03-26-2010 09:34 AM

Quote:

Originally Posted by blacky_5251 (Post 3912297)
Try grepping for " E " instead of just "E" - i.e. space E space in quotes.

------------------------------------------

grep -w " E " SystemOut.log sort -u >> sysfinal3



grep: sort: No such file or directory

------------------------------

grep -w " E " SystemOut.log >> sysfinal3



size of the file is zero.

dnaqvi 03-26-2010 09:45 AM

grep -w " A " SystemOut.log | sort | uniq >> sysfinal3


>cat sysfinal3

[2/6/10 9:39:15:007 PST] 0000aa21 AdminHelper A ADMN1020I: An attempt is made to stop the WebSphere_Portal server. (User ID = defaultWIMFileBasedRealm/admin)

This is the very first “ A “ type message in the SystemOut.log

But there are many more A types.
here are some of:

[2/6/10 9:39:20:439 PST] 00000012 ApplicationMg A WSVR0217I: Stopping application: Personalization_Workspace_6

[2/6/10 9:39:23:857 PST] 00000012 ApplicationMg A WSVR0220I: Application stopped: Personalization_Workspace_6

[2/6/10 9:39:23:859 PST] 00000012 ApplicationMg A WSVR0217I: Stopping application: PA_TplApp

[2/6/10 9:39:24:970 PST] 00000012 ApplicationMg A WSVR0220I: Application stopped: PA_TplApp

[2/6/10 9:39:24:971 PST] 00000012 ApplicationMg A WSVR0217I: Stopping application: PA_DynamicUIApp

[2/6/10 9:39:25:420 PST] 00000012 ApplicationMg A WSVR0220I: Application stopped: PA_DynamicUIApp

[2/6/10 9:39:25:421 PST] 00000012 ApplicationMg A WSVR0217I: Stopping application: PA_WCM_Admin

[2/6/10 9:39:26:520 PST] 00000012 ApplicationMg A WSVR0220I: Application stopped: PA_WCM_Admin

[2/6/10 9:39:26:521 PST] 00000012 ApplicationMg A WSVR0217I: Stopping application: PA_WCMLocalRendering

[2/6/10 9:39:27:869 PST] 00000012 ApplicationMg A WSVR0220I: Application stopped: PA_WCMLocalRendering

[2/6/10 9:39:27:870 PST] 00000012 ApplicationMg A WSVR0217I: Stopping application: PA_WCM_Authoring_UI

[2/6/10 9:39:29:225 PST] 00000012 ApplicationMg A WSVR0220I: Application stopped: PA_WCM_Authoring_UI

[2/6/10 9:39:29:226 PST] 00000012 ApplicationMg A WSVR0217I: Stopping application: PA_Resource_Manager

[2/6/10 9:39:30:410 PST] 00000012 ApplicationMg A WSVR0220I: Application stopped: PA_Resource_Manager

[2/6/10 9:39:30:412 PST] 00000012 ApplicationMg A WSVR0217I: Stopping application: PA_Login_Portlet_App

Thanks

blacky_5251 03-26-2010 02:51 PM

Sorry I gave you a silly answer before. The -w option in grep does what I was trying to do with " E ", and I didn't properly grasp your problem.

Try this command:-
Code:

grep -w E SystemOut.log | sort | uniq -f 3
The "-f 3" option to uniq tells it to ignore the first three fields when determining the uniqueness of each record.

dnaqvi 03-26-2010 10:49 PM

Quote:

Originally Posted by blacky_5251 (Post 3913646)
Sorry I gave you a silly answer before. The -w option in grep does what I was trying to do with " E ", and I didn't properly grasp your problem.

Try this command:-
Code:

grep -w E SystemOut.log | sort | uniq -f 3
The "-f 3" option to uniq tells it to ignore the first three fields when determining the uniqueness of each record.

-----------------------------------------------------------------

If I need to track multiple types.

On above command we are considering only E types but may be want W types too.
What to do?

Thanks

dnaqvi 03-26-2010 11:25 PM

Thanks.

This works

grep -w E SystemOut.log | sort | uniq -f 3

1) If I like to add more message types as below:


grep -w E A W SystemOut.log | sort | uniq -f 3

will it work?

2) Can I add total quantity of error on the same output?


LdapRegistryI A SECJ0419I: The user registry is currently connected to the LDAP server ldap: Total Appearance = 10

In SystemOut.log this message appeared 10 times.

D

rigor 03-27-2010 12:03 AM

Quote:

Originally Posted by dnaqvi (Post 3914015)
[...]
grep -w E A W SystemOut.log | sort | uniq -f 3

The following example would give any lines containing either W or E or A where there is a space before and after the character you are trying to match.

Quote:

egrep '( W )|( E )|( A )' SystemOut.log | sort | uniq -f 3

blacky_5251 03-27-2010 01:25 AM

Code:

grep -w [EAW]
Will locate all E, A and W errors.

blacky_5251 03-27-2010 01:32 AM

To count the number of error and warnings (in total), you could do this:-
Code:

CountErrors=$(grep -w E SystemOut.log | wc -l)
CountWarnings=$(grep -w W SystemOut.log | wc -l)
echo The number of errors is $CountErrors and the number of warnings is $CountWarnings

To count the number of different error types, try adding the -c option to the uniq command - i.e. uniq -c -f 3.

dnaqvi 03-27-2010 03:59 PM

Quote:

Originally Posted by blacky_5251 (Post 3914103)
To count the number of error and warnings (in total), you could do this:-
Code:

CountErrors=$(grep -w E SystemOut.log | wc -l)
CountWarnings=$(grep -w W SystemOut.log | wc -l)
echo The number of errors is $CountErrors and the number of warnings is $CountWarnings

To count the number of different error types, try adding the -c option to the uniq command - i.e. uniq -c -f 3.

-----

thanks
i will check monday morning usa (pst) time.

Many Thanks

dnaqvi 03-29-2010 09:15 AM

Uniq string is not working for for the multiple values

> grep -w [AI] SystemOut.log | sort | uniq -f 3

[3/29/10 0:01:45:464 PDT] 00000093 LdapRegistryI A SECJ0419I: The user registry is currently connected to the LDAP server ldap://00.00.00.00:123.
[3/29/10 5:00:10:117 PDT] 000000a0 CacheServiceI I DYNA1001I: WebSphere Dynamic Cache instance named services/cache/iwk/abspath initialized successfully.
[3/29/10 5:00:10:180 PDT] 000000a0 CacheServiceI I DYNA1001I: WebSphere Dynamic Cache instance named services/cache/iwk/abspathreverse initialized successfully.
[3/29/10 5:00:35:120 PDT] 0000009f CacheServiceI I DYNA1001I: WebSphere Dynamic Cache instance named services/cache/iwk/menu initialized successfully.
[3/29/10 5:01:46:113 PDT] 00000093 LdapRegistryI A SECJ0419I: The user registry is currently connected to the LDAP server ldap://00.00.00.00:123.
dn@dev2:/opt/IBM/WebSphere/PortalServer/log>

dnaqvi 03-29-2010 10:33 AM

I have noticed that single string is not working too.

> grep -w E SystemOut.log | sort | uniq -f 3



[3/29/10 5:37:32:540 PDT] 000000fe ServletWrappe E SRVE0068E: Could not invoke the service() method on servlet /jsp/index.jsp. Exception thrown : java.lang.NullPointerException
[3/29/10 7:03:14:566 PDT] 00000101 ServletWrappe E SRVE0068E: Could not invoke the service() method on servlet /jsp/index.jsp. Exception thrown : java.lang.NullPointerException
[3/29/10 7:13:30:308 PDT] 00000120 ServletWrappe E SRVE0068E: Could not invoke the service() method on servlet /jsp/index.jsp. Exception thrown : java.lang.NullPointerException
[3/29/10 5:37:32:599 PDT] 000000fe ServletWrappe E SRVE0068E: Could not invoke the service() method on servlet AutonomyJSPPortlet. Exception thrown : javax.servlet.ServletException
[3/29/10 8:02:01:636 PDT] 00000124 ServletWrappe E SRVE0068E: Could not invoke the service() method on servlet AutonomyJSPPortlet. Exception thrown : javax.servlet.ServletException:
[3/29/10 7:13:30:335 PDT] 00000120 ServletWrappe E SRVE0068E: Could not invoke the service() method on servlet AutonomyJSPPortlet. Exception thrown : javax.servlet.ServletException
[3/29/10 7:03:14:586 PDT] 00000101 ServletWrappe E SRVE0068E: Could not invoke the service() method on servlet AutonomyJSPPortlet. Exception thrown : javax.servlet.ServletException
[3/29/10 8:02:01:618 PDT] 00000124 ServletWrappe E SRVE0068E: Could not invoke the service() method on servlet /jsp/007recentInformation.jsp. Exception thrown : javax.servlet.ServletException: A required


[3/29/10 5:37:32:652 PDT] 000000fe ServletWrappe E SRVE0014E: Uncaught service() exception root cause AutonomyJSPPortlet: java.lang.NullPointerException
[3/29/10 7:13:30:358 PDT] 00000120 ServletWrappe E SRVE0014E: Uncaught service() exception root cause AutonomyJSPPortlet: java.lang.NullPointerException
[3/29/10 7:03:14:606 PDT] 00000101 ServletWrappe E SRVE0014E: Uncaught service() exception root cause AutonomyJSPPortlet: java.lang.NullPointerException
[3/29/10 8:02:01:629 PDT] 00000124 ServletWrappe E SRVE0014E: Uncaught service() exception root cause /jsp/007recentInformation.jsp: com.autonomy.aci.exceptions.MissingParameterException: A required
[3/29/10 8:02:01:643 PDT] 00000124 ServletWrappe E SRVE0014E: Uncaught service() exception root cause AutonomyJSPPortlet: javax.portlet.PortletException:

[3/29/10 2:19:24:510 PDT] 00000104 PortletRender E com.ibm.wps.engine.tags.PortletRenderTag doStartTag EJPEJ0066E: The portlet could not be rendered.
[3/29/10 5:37:32:700 PDT] 000000fe PortletRender E com.ibm.wps.engine.tags.PortletRenderTag doStartTag EJPEJ0066E: The portlet could not be rendered.
[3/29/10 7:03:14:624 PDT] 00000101 PortletRender E com.ibm.wps.engine.tags.PortletRenderTag doStartTag EJPEJ0066E: The portlet could not be rendered.
[3/29/10 7:13:30:372 PDT] 00000120 PortletRender E com.ibm.wps.engine.tags.PortletRenderTag doStartTag EJPEJ0066E: The portlet could not be rendered.



[3/29/10 3:03:16:239 PDT] 00000103 RepositorySer E Requested object could not be found.
[3/29/10 3:03:16:298 PDT] 00000101 RepositorySer E Requested object could not be found.
[3/29/10 5:28:25:269 PDT] 00000122 RepositorySer E Requested object could not be found.
[3/29/10 5:37:32:596 PDT] 000000fe LocalTranCoor E WLTC0017E: Resources rolled back due to setRollbackOnly() being called.
[3/29/10 7:03:14:584 PDT] 00000101 LocalTranCoor E WLTC0017E: Resources rolled back due to setRollbackOnly() being called.
[3/29/10 7:13:30:333 PDT] 00000120 LocalTranCoor E WLTC0017E: Resources rolled back due to setRollbackOnly() being called.


All times are GMT -5. The time now is 03:24 AM.