Merging two files

Guys,

I am having little problem with getting a daily report!

The daily process that I do is as follows

 
1. Unload Header for the report from the systables to one unl file, say Header.unl
2. Unload the data from the required table/tables to another unl file, say Data.unl
3. Send a mail consolidating these unl files as a report

What I have done for automating this is, written a script that unloads these files from the server. Here is where the trouble came :frowning:

I used,

 cat Header.unl ##All the header data will be in a single line(used perl for this)
echo ""
cat Data.unl

But this is turning out to be ugly. No formatting, proper spacing etc.

Please suggest any ideas that would transform the script to do as below,

 
1. Convert the Header.unl(with mulitple lines) to a single line file
2. Merge the new Header.unl and Data.unl to another file so that, all the columns are properly spaced, like one tabspace b/w every column

Header.unl

 
Head1|
Head2|
Head3|

Data.unl

 
1231|txt|this|
345|blah|that|
56741|awesome|plam|

Output expected :wink:

 
Head1    Head2    Head3
1231    txt    this
345    blah    that
56741    awesome    plam

Hello, PikK45:

paste -sd '\0' Header.unl | cat - Data.unl | sed 's/|$//; y/|/<tab>/'

Note: Replace <tab> with a literal tab character (or space if you prefer).

That assumes that the trailing pipe isn't intended to create an empty field at the end of every single line in your sample data. If it is, then this simpler alternative will do the job:

paste -sd '\0' Header.unl | cat - Data.unl | tr '|' '\t'

Regards,
Alister

With awk (assuming that Header.unl contains no blank lines between data lines):

awk 'NR==1{gsub(/\n/,"");RS="\n"} {sub(/\|$/,"");gsub(/\|/,"\t")}1' RS="" Header.unl Data.unl