0

Inside the shell script, one SQL query getting result set and export into abc.txt then after DML operation (INSERTION) perform & then result set of this statement export into xyz.txt. I want to convert all text into one file and then convert into CSV file.

abc.txt contained ->

ID    desc    before_cnts
01    abnd     112
02    bghs     115
03    ghjjk    119
04    tuhj     123
..    .....    ....

xyz.txt contained ->

ID   after_cnts
01   115
02   119
03   124
04   129
..   ...

When i merge both the file & manipulate the values then after got wrong values. But I want output.txt file like ->

ID  desc   before_cnts   after_cnts
01  abnd   112           115
02  bghs   115           119
03  ghjjk  119           124
04  tuhj   123           129
..  ....   ....          ....

Then after i will convert into CSV file. Could you please help to get proper output. Refer question here

terdon
  • 242,166

1 Answers1

2

This is what join is for:

$ join abc.txt xyz.txt
ID desc before_cnts after_cnts
01 abnd 112 115
02 bghs 115 119
03 ghjjk 119 124
04 tuhj 123 129

Or, if you also want them visually aligned:

$ join abc.txt xyz.txt | column -t
ID  desc   before_cnts  after_cnts
01  abnd   112          115
02  bghs   115          119
03  ghjjk  119          124
04  tuhj   123          129
terdon
  • 242,166