I have this piece of code that produces some output with printf statements on the console. I want to somehow collect the data into a .txt file when I run this code multiple times with different variables, for example if my program is called “produce”, I want to get the outputs of:
./produce 0 ./produce 1 ./produce 2
and so on. Any way of automating this? Thanks.
You can write a simple shell script for this.
Put the above code in a file like test.sh. And then run the command
sh test.shon the console and you should be seeing the file output.txt getting created with the desired output in it.Make sure to rename output.txt before running the script everytime.