通过下面的命令,我们可以从文件中打印重复行
uniq -d string file.txt但我们怎样才能在csv文件上做到呢?
我们只需要在csv文件的字段1,2上打印重复行--不包括字段3
FS - ",“
例如:
spark2-thrift-sparkconf,spark.history.fs.logDirectory,{{spark_history_dir}}
spark2-thrift-sparkconf,spark.history.fs.logDirectory,true
spark2-thrift-sparkconf,spark.history.Log.logDirectory,true
spark2-thrift-sparkconf,spark.history.DF.logDirectory,true预期成果:
spark2-thrift-sparkconf,spark.history.fs.logDirectory,{{spark_history_dir}}
spark2-thrift-sparkconf,spark.history.fs.logDirectory,true第二:
如何从csv文件中排除重复行(我的意思是仅删除字段1、2上的重复行)
预期产出:
spark2-thrift-sparkconf,spark.history.Log.logDirectory,true
spark2-thrift-sparkconf,spark.history.DF.logDirectory,true发布于 2017-08-22 08:11:22
cut前两个字段,按照您的建议对它们进行uniq,并使用结果对原始文件中的行进行grep:
cut -d, -f1,2 file.cvs |uniq -d|grep -Ff - file.cvs如果尚未对文件进行排序,则必须在uniq之前对其进行排序:
cut -d, -f1,2 file.cvs |sort|uniq -d|grep -Ff - file.cvs对于第二个问题(倒排结果),使用选项-u而不是-d:
cut -d, -f1,2 file.cvs |sort|uniq -u|grep -Ff - file.cvshttps://unix.stackexchange.com/questions/387590
复制相似问题