从列表到我的文件翻译性格 [英] Translating character from a list to my file

查看:121
本文介绍了从列表到我的文件翻译性格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多的文件,这些文件是这样的:

I have lots of files that look like this:

136
155
223
783
344
455
230
.
.
.

和其他文件像这样(字典):

And another file like this (the dictionary):

rs6427315   230
rs1171564   455
rs1609666   344
rs728917    155
rs728918    223
rs11264495  783
rs11805559  136
.           .
.           .
.           .

和我想要一个新的文件看起来像这样,那是从我的第一个文件中读取字符,并将其与对手在第1列从另一个文件替换:

And I want a new file that looks like this, that is reading the characters from my first file and substituting them with the match in column 1 from the other file:

rs11805559
rs728917
rs728918
rs11264495
rs1609666
rs1609666
rs1171564
rs6427315

在此先感谢

推荐答案

这可能是一种方式:

$ awk 'NR==FNR {a[$2]=$1; next} $1=a[$1]' file2 file1
rs11805559
rs728917
rs728918
rs11264495
rs1609666
rs1171564
rs6427315

说明

首先,它遍历第二个文件,并存储阵列 A [数字] = rxxxx 。然后,它遍历的第一个文件,并用其在数组中值替换字段。

Explanation

Firstly it loops through the second file and stores the array a[number]=rxxxx. Then it loops through the first file and replaces the field with its value in the array.

这篇关于从列表到我的文件翻译性格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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