xargs

Dear all ,
any suggest on xargs to combine from (1.txt and 2.txt) to output.txt ?

thanks a lot.

1.txt

0123 BUM-5M BUM-5M                                           93490481                63839
0124 BUM-5M BUM-5M                                             112112                   76
0125 BUM-5M BUM-5M                                              33707                   23

2.txt (customer list.txt)

0001 apple ABC company
0002 bananer BBB company
0123 Cat ccc ccc company
0124 David ddddddd dddd company
0125 Egg  eee eee  company
0126 rest rest company

...
..
.

change to output.txt

Cat ccc ccc company 
0123 BUM-5M BUM-5M                                           93490481                63839

David ddddddd dddd company
0124 BUM-5M BUM-5M                                             112112                   76

Egg  eee eee  company
0125 BUM-5M BUM-5M                                              33707                   23

You need awk, not xargs:

awk 'NR == FNR {
  idx = $1; sub(/[^ ]*  */, x)
  cus[idx] = $0
  next
  }
$1 in cus {
  printf "%s\n%s\n\n", cus[$1], $0
  }' 2.txt 1.txt  
awk 'NR==FNR{t=$1;sub($1 " ","",$0);a[t]=$0;next}{print a[$1] RS $0 RS}' 2.txt 1.txt
1 Like

thanks a lot. it is perfect.