Python修改常值內容

來源:互聯網
上載者:User

標籤:python

將第一行內容改為第二行的內容格式

REPLACE INTO `LogCenterDbName` VALUES (29, 1, ‘lt4_his‘);

REPLACE INTO `LogCenterDbName` VALUES (29, 1, ‘loghis_pool1‘,‘pjbhislt4‘);


原檔案

cat file.txt

REPLACE INTO `LogCenterDbName` VALUES (14, 0, ‘dx1_log‘);

REPLACE INTO `LogCenterDbName` VALUES (14, 1, ‘dx1_his‘);

REPLACE INTO `LogCenterDbName` VALUES (18, 0, ‘dx2_log‘);

REPLACE INTO `LogCenterDbName` VALUES (18, 1, ‘dx2_his‘);

REPLACE INTO `LogCenterDbName` VALUES (19, 0, ‘dx3_log‘);

REPLACE INTO `LogCenterDbName` VALUES (19, 1, ‘dx3_his‘);

REPLACE INTO `LogCenterDbName` VALUES (21, 1, ‘dx4_his‘);

REPLACE INTO `LogCenterDbName` VALUES (21, 0, ‘dx4_log‘);

REPLACE INTO `LogCenterDbName` VALUES (25, 0, ‘dx5_log‘);

REPLACE INTO `LogCenterDbName` VALUES (25, 1, ‘dx5_his‘);

REPLACE INTO `LogCenterDbName` VALUES (15, 0, ‘lt1_log‘);

REPLACE INTO `LogCenterDbName` VALUES (15, 1, ‘lt1_his‘);

REPLACE INTO `LogCenterDbName` VALUES (20, 0, ‘lt2_log‘);

REPLACE INTO `LogCenterDbName` VALUES (20, 1, ‘lt2_his‘);

REPLACE INTO `LogCenterDbName` VALUES (23, 0, ‘lt3_log‘);

REPLACE INTO `LogCenterDbName` VALUES (23, 1, ‘lt3_his‘);

REPLACE INTO `LogCenterDbName` VALUES (17, 0, ‘360_log‘);

REPLACE INTO `LogCenterDbName` VALUES (17, 1, ‘360_his‘);

REPLACE INTO `LogCenterDbName` VALUES (22, 0, ‘179_log‘);

REPLACE INTO `LogCenterDbName` VALUES (22, 1, ‘179_his‘);

REPLACE INTO `LogCenterDbName` VALUES (24, 0, ‘yy_log‘);

REPLACE INTO `LogCenterDbName` VALUES (24, 1, ‘yy_his‘);

REPLACE INTO `LogCenterDbName` VALUES (26, 0, ‘9377_log‘);

REPLACE INTO `LogCenterDbName` VALUES (26, 1, ‘9377_his‘);

REPLACE INTO `LogCenterDbName` VALUES (28, 0, ‘dx6_log‘);

REPLACE INTO `LogCenterDbName` VALUES (28, 1, ‘dx6_his‘);

REPLACE INTO `LogCenterDbName` VALUES (29, 0, ‘lt4_log‘);

REPLACE INTO `LogCenterDbName` VALUES (29, 1, ‘lt4_his‘);


指令碼內容

#!/usr/bin/env python#coding:utf-8f=open(‘file.txt‘,‘r‘)b=file(‘test.txt‘,‘a‘)for i in f:    i=i.split("‘")    q=i[1]    q=q.split(‘_‘)    zuo=q[0]    you=q[1]    format="‘pjb%s%s‘" % (you,zuo)    nr=str(i[0]+‘loghis_pool1 ,‘+format+i[2],)    b.write(nr)f.close()b.close()


修改後的檔案內容

cat test.txt

REPLACE INTO `LogCenterDbName` VALUES (14, 0, loghis_pool1 ,‘pjblogdx1‘);REPLACE INTO `LogCenterDbName` VALUES (14, 1, loghis_pool1 ,‘pjbhisdx1‘);REPLACE INTO `LogCenterDbName` VALUES (18, 0, loghis_pool1 ,‘pjblogdx2‘);REPLACE INTO `LogCenterDbName` VALUES (18, 1, loghis_pool1 ,‘pjbhisdx2‘);REPLACE INTO `LogCenterDbName` VALUES (19, 0, loghis_pool1 ,‘pjblogdx3‘);REPLACE INTO `LogCenterDbName` VALUES (19, 1, loghis_pool1 ,‘pjbhisdx3‘);REPLACE INTO `LogCenterDbName` VALUES (21, 1, loghis_pool1 ,‘pjbhisdx4‘);REPLACE INTO `LogCenterDbName` VALUES (21, 0, loghis_pool1 ,‘pjblogdx4‘);REPLACE INTO `LogCenterDbName` VALUES (25, 0, loghis_pool1 ,‘pjblogdx5‘);REPLACE INTO `LogCenterDbName` VALUES (25, 1, loghis_pool1 ,‘pjbhisdx5‘);REPLACE INTO `LogCenterDbName` VALUES (15, 0, loghis_pool1 ,‘pjbloglt1‘);REPLACE INTO `LogCenterDbName` VALUES (15, 1, loghis_pool1 ,‘pjbhislt1‘);REPLACE INTO `LogCenterDbName` VALUES (20, 0, loghis_pool1 ,‘pjbloglt2‘);REPLACE INTO `LogCenterDbName` VALUES (20, 1, loghis_pool1 ,‘pjbhislt2‘);REPLACE INTO `LogCenterDbName` VALUES (23, 0, loghis_pool1 ,‘pjbloglt3‘);REPLACE INTO `LogCenterDbName` VALUES (23, 1, loghis_pool1 ,‘pjbhislt3‘);REPLACE INTO `LogCenterDbName` VALUES (17, 0, loghis_pool1 ,‘pjblog360‘);REPLACE INTO `LogCenterDbName` VALUES (17, 1, loghis_pool1 ,‘pjbhis360‘);REPLACE INTO `LogCenterDbName` VALUES (22, 0, loghis_pool1 ,‘pjblog179‘);REPLACE INTO `LogCenterDbName` VALUES (22, 1, loghis_pool1 ,‘pjbhis179‘);REPLACE INTO `LogCenterDbName` VALUES (24, 0, loghis_pool1 ,‘pjblogyy‘);REPLACE INTO `LogCenterDbName` VALUES (24, 1, loghis_pool1 ,‘pjbhisyy‘);REPLACE INTO `LogCenterDbName` VALUES (26, 0, loghis_pool1 ,‘pjblog9377‘);REPLACE INTO `LogCenterDbName` VALUES (26, 1, loghis_pool1 ,‘pjbhis9377‘);REPLACE INTO `LogCenterDbName` VALUES (28, 0, loghis_pool1 ,‘pjblogdx6‘);REPLACE INTO `LogCenterDbName` VALUES (28, 1, loghis_pool1 ,‘pjbhisdx6‘);REPLACE INTO `LogCenterDbName` VALUES (29, 0, loghis_pool1 ,‘pjbloglt4‘);REPLACE INTO `LogCenterDbName` VALUES (29, 1, loghis_pool1 ,‘pjbhislt4‘);


本文出自 “YHT的營運筆記” 部落格,請務必保留此出處http://yht1990.blog.51cto.com/9014030/1937291

Python修改常值內容

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.