-2

FILE1:

at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:940)
        at com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:198)
        at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:712)
        at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.dispatch(SocketOrChannelConnectionImpl.java:469)
        at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.doWork(SocketOrChannelConnectionImpl.java:1230)
РЯа. 19, 2021 4:14:16 PM com.lhs.ccb.sfw.application.ServiceObjectImpl executeLocaleI
SEVERE: ServiceObjectI.executeLocaleI CONTRACT.WRITE

FILE 2:

Error code: CommonDomain.InvalidStateTransition
    at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1700)
    at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1558)
    at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:940)
    at com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:198)
    at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:712)

РЯа. 19, 2021 4:14:16 PM com.lhs.FrameworkExtension.bscs_core.d getErrorMessage WARNING: no localized text available for: ErrorCode : InvalidStateTransition BundleName: CommonDomain_ErrorDictionary Locale : en_US Reason : XMlResourceException: ResourceBundleManager: Can not find resource bundle 'CommonDomain_ErrorDictionary' РЯа. 19, 2021 4:14:16 PM com.lhs.FrameworkExtension.bscs_core.d getErrorMessage WARNING: no localized text available for: ErrorCode : InvalidStateTransition BundleName: CommonDomain_ErrorDictionary Locale : en_US Reason : XMlResourceException: ResourceBundleManager: Can not find resource bundle 'CommonDomain_ErrorDictionary' РЯа. 19, 2021 4:15:42 PM com.lhs.ccb.sfw.application.ServiceObjectImpl executeLocaleI SEVERE: ServiceObjectI.executeLocaleI CONTRACT.WRITE

FILE 3:

Error code: CommonDomain.InvalidStateTransition
    at com.lhs.ccb.sfw.application.ServiceObjectImpl.execute(Unknown Source)
    at com.lhs.cil.core.AggregatedServiceObjectImpl.execute(Unknown Source)
    at com.lhs.ccb.sfw.application.ServiceObjectImpl.executeLocaleI(Unknown Source)
    at com.lhs.cil.core.AggregatedServiceObjectImpl.executeLocaleI(Unknown Source)
    at com.lhs.ccb.soi.ServiceObjectIPOA._invoke(Unknown Source)

РЯа. 19, 2021 4:20:21 PM com.lhs.FrameworkExtension.bscs_core.d getErrorMessage WARNING: no localized text available for: ErrorCode : InvalidStateTransition BundleName: CommonDomain_ErrorDictionary Locale : en_US Reason : XMlResourceException: ResourceBundleManager: Can not find resource bundle 'CommonDomain_ErrorDictionary' РЯа. 19, 2021 4:20:21 PM com.lhs.FrameworkExtension.bscs_core.d getErrorMessage WARNING: no localized text available for: ErrorCode : InvalidStateTransition BundleName: CommonDomain_ErrorDictionary Locale : en_US Reason : XMlResourceException: ResourceBundleManager: Can not find resource bundle 'CommonDomain_ErrorDictionary' РЯа. 19, 2021 4:21:22 PM com.lhs.ccb.sfw.application.ServiceObjectImpl executeLocaleI SEVERE: ServiceObjectI.executeLocaleI CONTRACT.WRITE

Error code: CommonDomain.InvalidStateTransition at com.lhs.CommonDomain.bscs_core.ae.a(Unknown Source) at com.lhs.cil.core.AggregatedServiceObjectImpl.execute(Unknown Source) at com.lhs.ccb.sfw.application.ServiceObjectImpl.executeLocaleI(Unknown Source) at com.lhs.cil.core.AggregatedServiceObjectImpl.executeLocaleI(Unknown Source) at com.lhs.ccb.soi.ServiceObjectIPOA._invoke(Unknown Source)

РЯа. 19, 2021 4:21:22 PM com.lhs.FrameworkExtension.bscs_core.d getErrorMessage WARNING: no localized text available for: ErrorCode : InvalidStateTransition BundleName: CommonDomain_ErrorDictionary Locale : en_US Reason : XMlResourceException: ResourceBundleManager: Can not find resource bundle 'CommonDomain_ErrorDictionary' РЯа. 19, 2021 4:21:22 PM com.lhs.FrameworkExtension.bscs_core.d getErrorMessage WARNING: no localized text available for: ErrorCode : InvalidStateTransition BundleName: CommonDomain_ErrorDictionary Locale : en_US Reason : XMlResourceException: ResourceBundleManager: Can not find resource bundle 'CommonDomain_ErrorDictionary' РЯа. 19, 2021 4:26:22 PM com.lhs.ccb.sfw.application.ServiceObjectImpl executeLocaleI SEVERE: ServiceObjectI.executeLocaleI CONTRACT.WRITE

Error code: CommonDomain.InvalidStateTransition at com.lhs.ccb.sfw.application.ServiceObjectImpl.execute(Unknown Source) at com.lhs.cil.core.AggregatedServiceObjectImpl.execute(Unknown Source) at com.lhs.ccb.sfw.application.ServiceObjectImpl.executeLocaleI(Unknown Source) at com.lhs.cil.core.AggregatedServiceObjectImpl.executeLocaleI(Unknown Source) at com.lhs.ccb.soi.ServiceObjectIPOA._invoke(Unknown Source)

РЯа. 19, 2021 4:26:22 PM com.lhs.FrameworkExtension.bscs_core.d getErrorMessage WARNING: no localized text available for: ErrorCode : InvalidStateTransition BundleName: CommonDomain_ErrorDictionary Locale : en_US Reason : XMlResourceException: ResourceBundleManager: Can not find resource bundle 'CommonDomain_ErrorDictionary' РЯа. 19, 2021 4:26:22 PM com.lhs.FrameworkExtension.bscs_core.d getErrorMessage WARNING: no localized text available for: ErrorCode : InvalidStateTransition BundleName: CommonDomain_ErrorDictionary Locale : en_US Reason : XMlResourceException: ResourceBundleManager: Can not find resource bundle 'CommonDomain_ErrorDictionary' РЯа. 19, 2021 4:30:40 PM com.lhs.ccb.sfw.application.ServiceObjectImpl executeLocaleI SEVERE: ServiceObjectI.executeLocaleI CONTRACT.WRITE

I want to create a shell script which will read these files in a way that will read the first file and extract my SEVERE rows in severe1, then the WARNING rows in warning1. Then pass the second file so that the SEVERE rows in severe2, then the WARNING rows in warning2 the same for the last file (10 files). What is the easiest way to do this?

The way I did that check is as follows: **

for i in (ls *.log); do
cat *.log|grep "SEVERE" > severe$i.txt
cat *.log|grep "WARNING" > warning$i.txt
done;

**

1 Answers1

3

There are several issues with your code:


for i in (ls *.log); do
  • Instead of (...), it should be $(...), however, it is not needed at all, because ...
  • you should not parse the output of ls, rather use for f in *.log; do
  • Your $i is not a counter, but the file names, you have to add a counter manually. i=0 before the loop and increment, e.g. with i=$((i+1)) inside the loop. (And then use for f in *.log).

cat *.log|grep "SEVERE" > severe$i.txt

While this is not "wrong" by itself, there are still issues in this case.

  • grep reads from files, there is no need for cat:

    grep -h "SEVERE" *.log > severe$i.txt
    
  • Why do you read *.log anways when you want the messages from each file separately?

  • To improve performance, add -F option to your grep.

  • To not match wrong patterns but only whole words, add -w.

  • Good habit would be to double quote variable file names --> ... > "severe$i.txt"


So, in total, I'd do:

i=0
for f in *.log; do
    i=$((i+1))
    grep -Fw "SEVERE" "$f" > "severe$i.txt"
    grep -Fw "WARNING" "$f" > "warning$i.txt"
done

or all in a single awk:

awk '
    FNR==1{FILENUM+=1}
    /^SEVERE/{print > "severe"FILENUM".txt"}
    /^WARNING/{print > "warning"FILENUM".txt"}
' *.log
pLumo
  • 22,565