有效的方式来映射ID [英] Efficient way to map ids

查看:167
本文介绍了有效的方式来映射ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文本文件,

文件1数据,如

游戏用户数

A Rugby 2
A Football 2
B Volleyball 1
C TT 2
...

文件2

1 Basketball
2 Football
3 Rugby
...
90 TT
91 Volleyball
...

现在我想要做的就是添加另一列到文件2这样的,我有从文件2游戏作为一个额外的列对应的指数文件1。

Now what I want to do is add another column to File 2 such that I have the corresponding index of the game from File 2 as an extra column in File 1.

我在档案1.2万个条目所以,我想补充另一列从文件2.指定的游戏指数(基本上是行号或订单)我如何能有效地做到这一点。

I have 2 million entries in File 1. So I want to add another column specifying the index(basically the line number or order) of the game from file 2. How can I do this efficiently.

现在我做这行一行。从文件中读取1行,用grep从文件2对应的游戏其行号和保存/编写一个文件。

Right now I am doing this line by line. Reading a line from file 1, grep the corresponding game from file 2 for its line number and saving/writing that to a file.

这会带我的年龄。我怎么能加快这?

This will take me ages. How can I speed this up?

推荐答案

未测试

awk 'NR==FNR{a[$2]=$1;next}{print $0,a[$2]}' file2 file1

这篇关于有效的方式来映射ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆