【发布时间】:2016-03-16 03:45:20
【问题描述】:
我想读取 fileIn.txt(逗号分隔)并输出 fileOut.txt,其中仅包含与给定列的前 3 个不同值匹配的行。例如,我的输入文件如下所示:
fileIn.txt
#location,day,time
home,mon,01:00
office,mon,06:00
home,mon,10:00
office,tues,03:00
home,wed,08:00
home,wed,11:00
home,thurs,02:00
home,fri,01:00
diner,fri,07:00
party,fri,09:00
home,sat,02:00
mall,sat,06:00
home,sat,09:00
beach,sun,01:00
我只想选择前 3 天不同的行,以便我的输出文件如下所示:
fileOut.txt
#location,day,time
home,mon,01:00
office,mon,06:00
home,mon,10:00
office,tues,03:00
home,wed,08:00
home,wed,11:00
【问题讨论】:
-
可以假设输入文件已经排序了吗?
-
是的,你可以假设。