您的位置:首页 > 运维架构 > Shell

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

2015-03-27 17:45 1191 查看
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

两种方法 大家可以任选其一 这两个脚本我都是在线上用到的 没有问题
本文出自 “linuxyy” 博客,请务必保留此出处http://linuxyy.blog.51cto.com/9490250/1625786
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐