返回: Python基础 索引页
对 DBCA 执行 log 中,如下的信息,如果想要进行一番自动化的处理,作为先导的步骤,
希望把有时间输出的行筛选出来,并且把下面这种 PM/AM 之前的部分截取出来:
INFO: Dec 1, 2020 5:22:10 PM oracle.install.commons.util.Application pause INFO: Resume Database Configuration Assistant INFO: Feb 21, 2022 10:45:22 AM oracle.install.commons.flow.FlowWorker waitForCompletion INFO: Waiting for completion all forked tasks at state databaseOperationPage
先做一个截取的例子,比如,对于上述信息,希望抓到 "INFO: Dec 1, 2020 5:22:10 PM",
或者 "INFO: Feb 21, 2022 10:45:22 AM" 。
实验的程序如下:
第一段:
str='INFO: Dec 1, 2020 5:22:10 PM oracle.install.commons.util.Application pause' strlist = str.split('PM') print (strlist[0]) original_str='INFO: Dec 1, 2020 5:22:10 PM oracle.install.commons.util.Application pause' strlist = original_str.split('AM')if ( len(strlist[0]) == len (str) ) : print ('Not found'); else: print ('Found'); print ('Finished')
运行结果:
Not found Finished
第二段:
original_str='INFO: Dec 1, 2020 5:22:10 PM oracle.install.commons.util.Application pause' strlist = original_str.split('PM') print (strlist[0]) print ( len(strlist[0]) ) print ( len(original_str)) if ( len(strlist[0]) == len (str) ) : print ('Not found'); else: print ('Found'); print (strlist[0]) print ('Finished')
运行结果:
INFO: Dec 1, 2020 5:22:10 Found Finished
返回: Python基础 索引页