一個文件的某一列寫入到另外一個文件的行中shell與python

shell:python

  

cat tvm.shshell

#!/bin/shide



echo "[/opt/download:/opt/tvmcap]" >/opt/script/channels.listserver

for channels in `cat /root/channel.txt|awk '{print $2}'`ip

doit

        echo "wx.service.live.tvmining.com|shanghaidx|$channels|ipad|180" >>/opt/script/channels.listclass

        echo "wx.service.live.tvmining.com|shanghaidx|$channels|ipsd|180" >>/opt/script/channels.listtest

        echo "wx.service.live.tvmining.com|shanghaidx|$channels|iptv|180" >>/opt/script/channels.listawk

doneservice

python:

 

[root@localhost ~]# cat test.txt 

#!/usr/bin/env python

f1=open('channel.txt','r')

f2=open('channel.list','w+')

for line in f1.readlines():

    tmp = line.split()

    print >>f2, "wx.server.live.tvmining.com|test|%s|ipad|180" % tmp[1]

    print >>f2, "wx.server.live.tvmining.com|test|%s|ipsd|180" % tmp[1]

    print >>f2, "wx.server.live.tvmining.com|test|%s|iptv|180" % tmp[1]

f2.close

f1.close


兩種方法 你們能夠任選其一   這兩個腳本我都是在線上用到的  沒有問題

相關文章
相關標籤/搜索