我的剧本如下:
counter = 0
with open(output_file, 'a') as f_out:
with codecs.open(data_file, 'r', encoding='utf8') as f:
for line in f:
counter += 1
try:
created_at = datetime.strptime(line[:first_colon], '%Y-%m-%d').strftime('%Y-%m-%d')
except ValueError:
log('Parse Error at line ' + str(counter))
continue
f_out.write(str(counter)+','+line+'\n')
当我使用
sed -n '#counterhere#p' data_file
,我发现行不匹配。你知道吗
你知道这里发生了什么吗?你知道吗
编辑:
例如,在数据文件中,我们有:
2016-03-18,Content1
2016-03-#J,Content2
2016-03-20,Content3
因此,在输出文件中,我们有:
1,2016-03-18,Content1
3,2016-03-20,Content3
这样我就可以在数据文件中找到精确的行,使用如下方法:
sed -n '3p' data_file
如果没有,它应该返回“Content3”
在小文件中,一切都很顺利。但是因为我在大文件上运行它,所以我很难调试它。你知道吗
下面是我一直在使用的工作示例:
使用
data.csv
文件:给出
out.csv
:它具有
data.csv
中正确源行的正确行号。因此,这些行号可用于查找源文件中的信息:给了我
希望这有助于推动事情向前发展。你知道吗
相关问题 更多 >
编程相关推荐