I have columns of data arriving from standard output (in my case a call to mysql), and I would like to append at each loop the column in a file. How can I do?
Standard output:
a1
a2
....
an
Saving in a file called table.dat:
table.dat:
a1
a2
....
an
Then another output is produced:
Further standard output:
b1
b2
....
bn
Appending to table.dat:
table.dat:
a1 b1
a2 b2
.... ....
an bn
...and so on. I can use paste, but I need three steps:
line producing standard output > tmpfile;
paste prevfile tmpfile > table
mv table prevfile;
Is there a faster way, maybe by using awk?
This solution: Add a new column to the file produces an empty table.
paste tablefile <(program)to skip one temp file. If you havesponge, you can add| sponge tablefileto do the replacement in-place, otherwise you just need to use a temporary file and rename every iteration.[mysql call] | paste table - | sponge tableis exactly what I needed, thaks! Incredible this "sponge" in themoreutilsdebian package: I never heard about it!