Linux 如何根据第二个文本文件对文本文件中的行进行排序
我有两个文本文件 文件A.txt: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
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