파일 1:
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
파일 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
파일 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
첫 번째 파일을 읽는 것과 같은 방식으로 이 파일을 읽고 strict1에서 SEVERE 줄을 추출한 다음 warning1에서 WARNING 줄을 추출하는 쉘 스크립트를 만들고 싶습니다. 그런 다음 Severe2의 SEVERE 라인과 warning2의 WARNING 라인이 마지막 파일(10개 파일)과 동일하도록 두 번째 파일을 전달합니다. 이를 수행하는 가장 쉬운 방법은 무엇입니까?
제가 확인한 방법은 다음과 같습니다. **
for i in (ls *.log); do
cat *.log|grep "SEVERE" > severe$i.txt
cat *.log|grep "WARNING" > warning$i.txt
done;
**
답변1
코드에 몇 가지 문제가 있습니다.
for i in (ls *.log); do
- 반대로
(...)
, 그래야$(...)
하지만, 전혀 그럴 필요는 없습니다. 왜냐하면... - 출력을 구문 분석하면 안 됩니다.
ls
, 대신 사용for f in *.log; do
- 카운터
$i
가 아니라 파일 이름이므로 카운터를 수동으로 추가해야 합니다. 내부 루프i=0
와 같은 루프 및 증분 전 .i=$((i+1))
(그런 다음 사용for f in *.log
).
cat *.log|grep "SEVERE" > severe$i.txt
이 사건 자체에는 '잘못'이 없지만, 이 사건에는 여전히 문제가 있습니다.
grep
파일에서 읽기, 다음이 필요하지 않습니다cat
.grep -h "SEVERE" *.log > severe$i.txt
*.log
각 파일의 메시지를 별도로 읽고 싶을 때 왜 읽어야 할까요?-F
성능 을 향상하려면grep
.잘못된 패턴을 매칭하지 않고 전체 단어만 매칭하려면 를 추가하세요
-w
.좋은 습관은 변수 파일 이름을 큰따옴표로 묶는 것입니다 -->
... > "severe$i.txt"
요약하면 다음과 같습니다.
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
또는 모두 하나로 awk
:
awk '
FNR==1{FILENUM+=1}
/^SEVERE/{print > "severe"FILENUM".txt"}
/^WARNING/{print > "warning"FILENUM".txt"}
' *.log