Correct usage for coreutils join and sort

…衆ロ難τιáo~ 提交于 2020-01-06 12:29:11

问题


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?


回答1:


Basically :

join <(sort file1) <(sort file2) 


来源:https://stackoverflow.com/questions/15133894/correct-usage-for-coreutils-join-and-sort

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!