#!/bin/bash awk -F " " ' function trim(str){ sub(/^[ ]*/,"",str); sub(/[ ]*$/,"", str); return str; } NR==FNR{ a[trim($1)] = $0 } NR > FNR{ if(a[trim($4)]){ print $0" "a[$4] }else{ #print trim($4) } } ' result_2 ueg
#!/bin/bash awk -F " " ' function trim(str){ sub(/^[ ]*/,"",str); sub(/[ ]*$/,"", str); return str; } NR==FNR{ a[trim($1)] = $0 } NR > FNR{ if(a[trim($4)]){ print $0" "a[$4] }else{ #print trim($4) } } ' result_2 ueg