I have several data files. For example
sales.txt (the original file has 13 columns)
Date Unit $$ employee# abc def jkl mno pqr
Dec1 10 500 2 1 2 3 4 5
Dec2 12 450 3 6 7 8 9 10
Dec3 13 550 3 11 12 13 14 15
Dec4 15 600 3 16 17 18 19 20
...
...
supply.txt (original one has 3 columns)
Date Unit cost source1 source2
Dec1 10 300 5 5
Dec2 12 350 5 7
Dec3 13 350 7 6
Dec4 15 400 6 9
...
...
And I have 3 other files which have 2 columns in each. What I am trying to do is match the date in all these files and copy the lines in a single file. The code I am using for this is:
# count the number of rows in the file
file="sales.txt"
N=$(awk -F, '{rows++} END{print rows}' $file)
for row in $(eval echo {2..$N})
do
pattern=$(awk -v r=$row 'FNR==r {print $1}' $file);
paste <(awk -v line=$row 'FNR==line{print $0}' $file)
<(awk -v line=$row 'FNR==line{$1=""; print $0}' supply.txt)
<(awk -v line=$row 'FNR==line{print $2}' otherfile1.txt)
<(awk -v line=$row 'FNR==line{print $2}' otherfile2.txt)
<(awk -v line=$row 'FNR==line{print $2}' otherfile3.txt) >> account.txt
done
It is working in copying and finding the lines but the format in the output file is something like this:
Dec1 10 500 2 1 2 3 4 5 10 300 5 5
1 # comes from otherfile1
2 # comes from otherfile2
3 # comes from otherfile3
Dec2 12 450 3 6 7 8 9 10 12 350 5 7
4
5
6
...
...
I want them to be on the same line. I have tried many techniques found in this forum but none of them has worked for me. Please help