如何读取多个文件

如何读取多个文件

如何读取多个文件并仅提取某些行并将它们写入各自适当的文件中示例:

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*

相关内容