我有两个脚本,一个映射器和一个减速器。两者都从csv阅读器获取输入。映射器脚本应该从制表符分隔的文本文件中获取输入,数据集.csv,reducer的输入应该是映射器的输出。我想把减速机的输出保存到一个文本文件中,输出.txt. 正确的命令链是什么?在
制图员:
#/usr/bin/python
import sys, csv
reader = csv.reader(sys.stdin, delimiter='\t')
writer = csv.writer(sys.stdout, delimiter='\t', quotechar='"', quoting=csv.QUOTE_ALL)
for line in reader:
if len(line) > 5: # parse only lines in the forum_node.tsv file
if line[5] == 'question':
_id = line[0]
student = line[3] # author_id
elif line[5] != 'node_type':
_id = line[7]
student = line[3] # author_id
else:
continue # ignore header
print '{0}\t{1}'.format(_id, student)
减速器:
^{pr2}$
将文件管道连接在一起:
< dataset.csv
提供mapper.py
上的CSV文件,|
将stdout重定向到另一个comment。另一个命令是python reducer.py
,并且> output.txt
将该脚本中的stdout
连接到`输出.txt. 在相关问题 更多 >
编程相关推荐