一个文件的某一列写入到另一个文件的行中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
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
相关文章推荐
- java 实现读一个txt文件 写入到另一个txt文件
- 每天学点linux--(用shell实现将一个文件夹下面的所有文件拷贝到另一个文件夹下/shell下如何重命名一个文件)
- python读取大文件并逐行写入另外一个文件
- python将某一目录下的多个文件合并为一个文件
- IO流_把一个文件中的字符串排序后再写入另一个文件案例
- 将一个文件的内容写入到另一个文件
- 《Java examples in a nutshell》书中一个关于列出某一目录下的所有目录与文件的程序源代码
- python:从excel中读出接口协议,将部分响应结果写入另一个excel文件
- python (1)一个简单的爬虫: python 在windows下 创建文件夹并写入文件
- 读取一个文件,然后排序,再写入另一个文件
- 向一个文件写入信息并读出写入另一个文件
- Python怎么在一个文件中的类调用另一个文件中的类
- java 把一个文件写入到另一个文件中
- 将一个文件的内容写入到另一个文件中(字节流)
- python 将一个文件中内容添加到另一个文件指定位置
- perl将一个文件中的特定行写入到另一个文件中
- python实现一个文件传递参数并执行另一个文件
- python 文件处理模块使用,对一个文件追加写入
- Linux常用命令:文件解压缩、去重、合并为一个文件、一个文件的指定行写入另一个文件(不断更新中...)
- python 从shell读取指定文件以及写入指定文件