微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用点和数字对字母进行排序的排序选项

如何解决使用点和数字对字母进行排序的排序选项

我想用 join 合并两个文件 文件 1 就像:

Salmonella_enterica_subsp_enterica_Infantis   lcl|CP052796.1_prot_QJV25804.1_4153
...

而 file2 是:

...
Prot    lcl|CP052796.1_prot_QJV25804.1_4153 98.701  100
...

我想得到一个这样的文件

Prot Salmonella_enterica_subsp_enterica_Infantis lcl|CP052796.1_prot_QJV25804.1_4153 98.701 100 

我尝试使用 join -1 2 -2 2 -o 2.1 1.1 2.2 2.3 2.4 file1 file2 但 join 给出警告“join: file2: is not sorted”。

我尝试在这之前对这两个文件进行排序,例如 sort -k2,2 file1,但它不起作用。对这种类型的链条进行排序有什么想法吗? 谢谢!

解决方法

如果 awk 是您的选择,请您试试:

awk '
    # the following block processes File1
    NR==FNR {
        f1[$2] = $1     # associate the 1st field with 2nd field in File1
        next
    }
    # the following block processes File2
    f1[$2] {            # if the 2nd field is found in File1
        print $1,f1[$2],$2,$3,$4
    }
' File1 File2

使用提供的示例输出:

Prot Salmonella_enterica_subsp_enterica_Infantis lcl|CP052796.1_prot_QJV25804.1_4153 98.701 100

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。