Sed solutions
You could generate the string you want with printf
and substitute the end of each line using sed:
$ num=5
$ sed 's/$/'"$(for ((i=0; i<num; ++i)); do printf '\t%s' '0.0'; done)"'/' in.txt
a 0.0 0.0 0.0 0.0 0.0
b 0.0 0.0 0.0 0.0 0.0
c 0.0 0.0 0.0 0.0 0.0
where the value assigned to num
is the number of columns to be added to your file.
The substitution replaces each line end ($
) with the output of this command:
for (( i=0; i < num; ++i )); do
printf '\t%s' '0.0'
done
If you don't mind using seq
, this could be simplified to
sed 's/$/'"$(printf '\t0.0%.0s' $(seq 1 $num))"'/' in.txt
i.e., the command in the substitution is the one-liner
printf '\t0.0%.0s' $(seq 1 $num)
See for example the question How can I repeat a character in bash? for many options how to repeat a string in Bash using various tools.
Awk solution
This takes num
as the number of columns to be added and uses a tab as the field separator:
awk -v num=5 -v OFS="\t" '{for (i=1; i<=num; ++i) $(NF+1) = "0.0"}1' in.txt
The for loop assigns 0.0
to the field one past the last, num
times; the 1
gets the line printed.