我有两个文件file1和file2。 file2中的某些名称不在file1中。我想在file1中添加这些名称。
文件1
anna 14/2 = 7.0
alex 23/6 = 3.8
deffy 27/3 = 9.0
hobert 24/9 = 2.7
file2的
anna
alex
benny
cathar
deffy
hobbert
sam
我想要的输出如下所示。
anna 14/2 = 7.0
alex 23/6 = 3.8
benny 0/0 = 0
cathar 0/0 = 0
deffy 27/3 = 9.0
hobert 24/9 = 2.7
sam 0/0 = 0
你的帮助将不胜感激!
答案 0 :(得分:1)
另一个awk
,
awk 'NR==FNR{a[$1]=$0;next} {$0=($1 in a )?a[$1]:$0" 0/0 = 0"}1' file1 file2
答案 1 :(得分:1)
kent$ awk 'NR==FNR{a[$1]=$0;next}a[$0]{print a[$0];next}{print $1,"0/0 = 0"} ' f1 f2|column -t
anna 14/2 = 7.0
alex 23/6 = 3.8
benny 0/0 = 0
cathar 0/0 = 0
deffy 27/3 = 9.0
hobbert 0/0 = 0
sam 0/0 = 0