Reputation: 788
I have an executable file that provides a float random number that displays in the terminal such as
./my_exe
Then the output terminal will be
0.6
Now, I will run the my_exe
in the loop such as
for i in {1..10}
do
./my_exe
./my_exe
./my_exe
done
I want to write the output to the file such as the output of command in the same iteration will display in the same row with tab \t
and the next iters will be in the new line
The output should be
0.6 0.7 0.1
0.2 0.2 0.4
...
How can I do it in shell file? This is my current code
for i in {1..10}
do
./my_exe >> out.txt
echo -e "\t" >> out.txt
./my_exe >> out.txt
echo -e "\t" >> out.txt
./my_exe >> out.txt
echo -e "\t" >> out.txt #write tab
done
Upvotes: 2
Views: 355
Reputation: 785521
You can use printf
:
for i in {1..10}; do
printf '%s\t%s\t%s\n' $(./my_exe) $(./my_exe) $(./my_exe)
done > out.txt
Upvotes: 1