一个文件的某一列写入到另一个文件的行中shell与python

shell:

  

cat tvm.sh

#!/bin/sh



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

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

do

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

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

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

done

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


两种方法 大家可以任选其一   这两个脚本我都是在线上用到的  没有问题

你可能感兴趣的:(shell,python,某件写入)