I want to insert a counter into a text file using sed. For example, the file has the following content:
please.add.number.00
Here is the script I'm using:
for i in $(seq 0 10)
do
sed -i 's/please.add.number.00/please.add.number.$i/' filename.txt
done
But the value ($i) in the file doesn't change. I want to substitute the value of $i in this line of filename.txt. I would appreciate any help to fix this issue!
seq 10 10?$(seq 10 10)just produces10so there's no looping. If there was a loop (say 'seq 10 20'), this would replace all...number.00with...number.10and no more replacements would take place, because there would be no more '...number.00' left after doing the first replacement. Also note that the dots inplease.add.number.00are wildcards while those inplease.add.number.$iare literal periods.