I want to put the output data from unix command to a csv file. Suppose the output which I am getting is :
A
B
C
I want to put this data in .csv
Try this :
printf '%s\n' A B C | paste -sd ' ' >> file.csv
or more classical for a CSV (delimiter with a ,
:
printf '%s\n' A B C | paste -sd ',' >> file.csv
printf '%s\n' A B C
is just an example to have the same sample input as you. My solution works with spaces in a same line too.
EDIT from your comments, you seems to need to treat with a for
loop, so :
for i in {0..5}; do printf '%s\n' {A..C} | paste -sd " " >> file.csv; done
or in pseudo code :
for ...:
unix_command | paste -sd " " >> file.csv
endfor