Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何根据第二个文本文件对文本文件中的行进行排序_Linux_Sorting_Vim_Text_Awk - Fatal编程技术网

Linux 如何根据第二个文本文件对文本文件中的行进行排序

Linux 如何根据第二个文本文件对文本文件中的行进行排序,linux,sorting,vim,text,awk,Linux,Sorting,Vim,Text,Awk,我有两个文本文件 文件A.txt: john peter mary alex cloey 文件B.txt peter does something cloey looks at him franz is the new here mary sleeps 我想 合并两者 将一个文件按另一个文件排序 将未知的B行放在末尾 像这样: john peter does something mary sleeps alex cloey looks at him franz is the new he

我有两个文本文件

文件A.txt:

john
peter
mary
alex
cloey
文件B.txt

peter does something
cloey looks at him
franz is the new here
mary sleeps
我想

  • 合并两者
  • 将一个文件按另一个文件排序
  • 将未知的B行放在末尾
像这样:

john
peter does something
mary sleeps
alex
cloey looks at him
franz is the new here
上面将以“随机”顺序打印fileB中的其余项目(有关详细信息,请参阅)。如果这是一个问题,那么编辑您的问题,以澄清您对需要打印的订单的要求


它还假设每个文件中的键是唯一的(例如,
peter
在每个文件中仅作为键值出现一次)。如果不是这样,请再次编辑您的问题,以包括某个键在您的输入/输出中多次出现的情况,并另外解释您希望如何处理该问题。

以及您尝试了什么?
$ awk '
    NR==FNR { b[$1]=$0; next }
    { print ($1 in b ? b[$1] : $1); delete b[$1] }
    END { for (i in b) print b[i] }
  ' fileB fileA
john
peter does something
mary sleeps
alex
cloey looks at him
franz is the new here