请教如何删除 6 万 txt 中重复的行

2015-04-23 11:34:09 +08:00
 holinhot

文本1中:

123.com.     3600    IN      SOA     ns1.dns.com. dns.dns.com. 1419473850 3600 3600 3600 3600
123.com.     3600    IN      A       2.2.2.2
123.com.     3600    IN      NS      ns2.dns.com.
123.com.     3600    IN      NS      ns1.dns.com.
123.com.     3600    IN      SOA     ns1.dns.com. dns.dns.com. 1419473850 3600 3600 3600 3600

文本2中

aaaa.com.     3600    IN      SOA     ns1.youdns.com. dns.youdns.com. 1419473850 3600 3600 3600 3600
aaaa.com.     3600    IN      A       11.1.1.1.1
aaaa.com.     3600    IN      NS      ns2.youdns.com.
aaaa.com.     3600    IN      NS      ns1.youdns.com.
aaaa.com.     3600    IN      SOA     ns1.youdns.com. dns.youdns.com. 1419473850 3600 3600 3600 3600

删除每个文本中重复的行
像文本1中

123.com.     3600    IN      SOA     ns1.dns.com. dns.dns.com. 1419473850 3600 3600 3600 3600

这行重复了去掉重复的一行

文本2中

aaaa.com.     3600    IN      SOA     ns1.youdns.com. dns.youdns.com. 1419473850 3600 3600 3600 3600

重复了 去掉重复的一行。
我也不知道为什么为有两条SOA记录 真是奇怪

10144 次点击
所在节点    Python
66 条回复
holinhot
2015-04-23 15:37:15 +08:00
@prinzchao 这个厉害 你手动从6w txt复制到excel?
chengzhoukun
2015-04-23 15:38:45 +08:00
用SQL也可以吧
chengzhoukun
2015-04-23 15:38:45 +08:00
用SQL
holinhot
2015-04-23 15:39:30 +08:00
@GreenJoson 不是10w行吧。是6w个txt 每个txt大概10来行
holinhot
2015-04-23 15:41:24 +08:00
@chengzhoukun 最终用api入库
MarioLuisGarcia
2015-04-23 15:43:18 +08:00
vim里 :sort u
搞定!
tikazyq
2015-04-23 15:44:50 +08:00
cat <filename> | sort | uniq >> unique.txt

6万行数据不算大,直接unix操作就ok
IssacTseng
2015-04-23 16:20:31 +08:00
@holinhot 临时处理某个文档数据当然可以这样啊,6W行数据对现在的电脑配置来说毫无难度吧。
Anybfans
2015-04-23 16:33:46 +08:00
为什么大家看不清。。。人家说的是6个txt文件。。。。。。。。。
sbboy
2015-04-23 16:51:49 +08:00
@Anybfans 6万个吧。。。
touch
2015-04-23 16:57:41 +08:00
既然最终要入库的那不是一条sql语句的事
raman
2015-04-23 17:14:07 +08:00
这里 sort - u file.txt
idblife
2015-04-23 17:17:06 +08:00
导入数据库里操作一下
anexplore
2015-04-23 17:20:18 +08:00
sort -u src.txt > des.txt 就可以搞定了...
likexian
2015-04-23 17:39:15 +08:00
iiilii
2015-04-23 17:58:25 +08:00
这么多人都没看懂楼主的问题,6万个txt文件,每个文件10几行。
incompatible
2015-04-23 18:00:04 +08:00
python里没有 既能保持添加顺序、又能滤重 的数据结构?
类似Java里的LinkedHashSet
staticor
2015-04-23 18:25:35 +08:00
@incompatible ordereddict collections中的
mucid
2015-04-23 18:48:43 +08:00
cat *.txt | sort | uniq > all.txt
Jaylee
2015-04-23 19:02:56 +08:00
@mucid sort -u 就可以

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/185684

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX