여러 파일을 읽는 방법

여러 파일을 읽는 방법

여러 파일을 읽고 특정 줄만 추출하여 각각의 적절한 파일에 쓰는 방법 예:

file1.txt - file1_output;
file2.txt - file2_output;
file3.txt - file3_output;
file4.txt - file4_output;
file5.txt - file5_output;
more *.log | cat 
cat *.log | tee file1.txt file2.txt
File1:
    at com.lhs.ccb.sfw.application.ServiceObjectImpl.validate(Unknown Source)
    at com.lhs.cil.core.AggregatedServiceObjectImpl.validate(Unknown Source)
    at com.lhs.ccb.sfw.application.ServiceObjectImpl.validateI(Unknown Source)
    at com.lhs.ccb.soi.ServiceObjectIPOA._invoke(Unknown Source)
    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.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:519)

РЯа. 19, 2021 4:14:16 PM com.lhs.ccb.sfw.application.ServiceObjectImpl executeLocaleI
SEVERE: ServiceObjectI.executeLocaleI CONTRACT.WRITE

File2:
Error code: CommonDomain.InvalidStateTransition
    at com.lhs.CommonDomain.bscs_core.ae.a(Unknown Source)
    at com.lhs.Contract.bscs_core.services.ContractWrite.a(Unknown Source)
    at com.lhs.cil.core.AggregatedServiceObjectImpl.executeLocaleI(Unknown Source)
    at com.lhs.ccb.soi.ServiceObjectIPOA._invoke(Unknown Source)
    at com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:198)
    at com.sun.corba.se.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:519)

РЯа. 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

File3:
Error code: CommonDomain.InvalidStateTransition
    at com.lhs.CommonDomain.bscs_core.ae.a(Unknown Source)
    at com.lhs.Contract.bscs_core.services.ContractWrite.a(Unknown Source)
    at com.lhs.Contract.bscs_core.services.ContractWrite.execute(Unknown Source)
    at com.lhs.cil.core.LocalCommandAdapter.localExecute(Unknown Source)
    at com.lhs.cil.core.AggregatedServiceObjectImplProxy.execute(Unknown Source)
    at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1558)
    at com.sun.corba.se.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:519)

РЯа. 19, 2021 4:15:42 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.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:17:19 PM com.lhs.ccb.sfw.application.ServiceObjectImpl executeLocaleI
SEVERE: ServiceObjectI.executeLocaleI CONTRACT.WRITE

OUTPUT:
FILE1_OUTPUT: SEVERE line... from File1
FILE2_OUTPUT: SEVERE line... from File2
FILE3_OUTPUT: SEVERE line... from File3

***SEVERE 라인은 항상 다른 위치에 있습니다.

답변1

awk나는 다음을 사용합니다 :

awk 'FNR==1{ close(ofname); ofname="output_"FILENAME } 
  /^SEVERE/{ print >ofname }' infile*

관련 정보