# read keys
with open('file1', 'r') as fd:
keys = fd.read().splitlines()
# output keys
print '\t'.join(keys)
# read data file, with header line and content
with open('file2', 'r') as fd:
headers = fd.readline().split()
while True:
line = fd.readline().split()
if len(line) == 0:
break
print '\t'.join([line[headers.index(x)] for x in keys if x in headers])
只能使用bash来执行此操作:
注意
您的示例输出不正确,因为这里有“Ruby”,但在file1示例中,您的“Rubby”Ruby=/=Rubby
输出
^{pr2}$Python中一个在流中执行工作的示例(即:在开始输出之前不需要加载完整的文件):
输出:
^{pr2}$相关问题 更多 >
编程相关推荐