I'm running a command that outputs a list of numbers. I am using a for loop to run the command 5 times. For each output, I want to append those numbers to corresponding rows in an existing text file.
Command output:
# execute_command
20
30
480
50
Command with loop
for i in {1..5};
# execute_command
Command output with loop
20
30
480
50
30
50
60
70
90
20
20
40
40
35
60
70
90
50
40
10
Before
This is just a text file I created.
cat:
rabbit:
car:
can:
After
I want to append the command outputs to that existing text file.
first iteration
cat: 20
rabbit: 30
car: 480
can: 50
second iteration
cat: 20, 30
rabbit: 30, 50
car: 480, 60
can: 50, 70
third iteration
cat: 20, 30, 90
rabbit: 30, 50, 20
car: 480, 60, 20
can: 50, 70, 40
fourth iteration
cat: 20, 30, 90, 40,
rabbit: 30, 50, 20, 35
car: 480, 60, 20, 60
can: 50, 70, 40, 70
fifth iteration
cat: 20, 30, 90, 40, 90
rabbit: 30, 50, 20, 35, 50
car: 480, 60, 20, 60, 40
can: 50, 70, 40, 70, 10
Please help me. Thanks very much!