I would like to add a prefix in each new line of my command output.
runcommand1 | "[prefix1]" + log > logfile &
runcommand2 | "[prefix2]" + log > logfile &
^
Second one will overwrite first opened logfile
you have to append ">>" second one
Below mentioned few commands may help you.
You can use sed
yourcommand1 | sed 's/^/[prefix1] /' > logfile &
You can use awk
yourcommand1 | awk '{ print "[prefix1]", $0 }' > logfile &
yourcommand2 | awk '{ print "[prefix2]", $0 }' >> logfile &
if you want to pass prefix string to awk then
yourcommand1 | awk -v prefix="[prefix1]" '{ print prefix, $0 }' > logfile &
yourcommand2 | awk -v prefix="[prefix2]" '{ print prefix, $0 }' >> logfile &
OR
mystring1="[prefix1]"
mystring2="[prefix2]"
yourcommand1 | awk -v prefix="$my_string1" '{ print prefix, $0 }' > logfile &
yourcommand2 | awk -v prefix="$my_string2" '{ print prefix, $0 }' >> logfile &
If that's not all you need then update your question to show some more truly representative sample input (which you receive after running runcommand1/runcommand2) and expected output.