Python re Regular Expression instance 1

Source: Internet
Author: User

#! /Usr/bin/env python
#-*-Coding: UTF-8 -*-
# Filename: file_process.py
# Function:
# Author: Liu Hongbo
# Date: 2012-05-07

Import glob
Import OS
Import re


# Log file directory
V_log_dir = '/etl/aiinsight/bin/py'

# Target file
F_tab1 = open ('/etl/aiinsight/bin/py/tab_pai_tab.txt', 'w ')
F_tab2 = open ('/etl/aiinsight/bin/py/tab_into_insert.txt', 'w ')


OS. chdir (v_log_dir)


# Display files of the specified type

# Query Regular Expressions
P1 = re. compile ('wwnew \. [\ w] + | DW \. [\ w] + | REPORT \. [\ w] + | TBOWNER \. [\ w] + ')
P2 = re. compile ('insert [\ s] + INTO [\ s] + WWNEW \. [\ w] + | INSERT [\ s] + INTO [\ s] + DW \. [\ w] + | INSERT [\ s] + INTO [\ s] + REPORT \. [\ w] + | INSERT [\ s] + INTO [\ s] + TBOWNER \. [\ w] + ')

For v_file in glob. glob ('*. log '):
F = open (v_file)
For line in f:
For v_tab in p1.findall (line. upper ()):
F_tab1.write (v_file + ',' + v_tab + '\ n ')
For v_tab in p2.findall (line. upper ()):
F_tab2.write (v_file + ',' + v_tab + '\ n ')
F. close ()

F_tab1.close ()
F_tab2.close ()

 

From drop-down stone

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.