Copy Column Multiple Times

Hello,
I wonder if it my problem can be solved. Inside File1.txt, there are 3 columns. Inside File 2.txt, contain certain variable(in this case, only "3"). So I want to : (copy File 1 x Variable in File 2). Expected result are File 3.txt.
Any help are really appreciated.

File 1.txt

-92.033 -105.36 -5.38472
-34.8985 -103.205 -2.71757

File 2.txt

3
3

File 3.txt

-92.033 -105.36 -5.38472 -92.033 -105.36 -5.38472 -92.033 -105.36 -5.38472
-34.8985 -103.205 -2.71757 -34.8985 -103.205 -2.71757 -34.8985 -103.205 -2.71757

Try this...

awk 'NR==FNR{_1[$0]++;next}{for(i in _1){for(j=1;j<=i;j++){printf $0 FS}printf "\n"}}' 
File2.txt File1.txt > File3.txt

--ahamed

The script succeed to copy into File3.txt , but the multiplying number (based on variable File2.txt) is not correct. In above case, I try using "3", and it is perfectly working. But when I change the variable File2.txt into "9", it multiplies it into 89 times..

A small change... Try this...

awk 'NR==FNR{_1[$0]++;next}{for(i in _1){for(j=1;j<=i+0;j++){printf $0 FS}printf "\n"}}'  
File2.txt File1.txt > File3.txt

--ahamed

1 Like

Working like a charm..
I wonder about the meaning of this command. I really want to learn.