正确的使用coreutils加入和排序 [英] Correct usage for coreutils join and sort

查看:146
本文介绍了正确的使用coreutils加入和排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用标准的命令行工具 join 来连接两个文件。根据文档,两个输入文件需要为此排序。最初,我只是通过 sort 来实现这一点,但是这仍然导致错误,如join:file 2不是按排序顺序。然后我仔细研究了一下,发现我应该使用 sort -k 1b,1 ,但是这似乎没有帮助。我甚至玩的地方(设置 LANG = C LANG = EN_en ),但似乎没有工作。 / p>

到目前为止我试过:




  • cat x |排序| join -j 1 a -

  • cat x |排序-k1b,1 | join -j 1 a -

  • cat x | LANG = C sort -k1b,1 | join -j 1 a -

  • cat x | LANG = EN_en sort -k1b,1 | join -j 1 a -



那么,如何在未排序的文件上正确使用连接? p>

解决方案

基本上:

  join <(sort file1)<(sort file2)


I am trying to use the standard command-line tool join to join two files. According to the documentation, both input files need to be sorted for this. Initially I just piped them through sort to achieve this, but this still resulted in errors like "join: file 2 is not in sorted order". I then looked into this a bit more closely and found that I was supposed to use sort -k 1b,1, but that didn't seem to help either. I even played around with the locales (setting LANG=C or LANG=EN_en) but nothing seems to work.

So far I tried:

  • cat x | sort | join -j 1 a -
  • cat x | sort -k1b,1 | join -j 1 a -
  • cat x | LANG=C sort -k1b,1 | join -j 1 a -
  • cat x | LANG=EN_en sort -k1b,1 | join -j 1 a -

So, how do I use join correctly on unsorted files?

解决方案

Basically :

join <(sort file1) <(sort file2) 

这篇关于正确的使用coreutils加入和排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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