I want to replace a string in a text file with a sequence of numbers such as 1 2 3 4 5 6 7 preferably using sed.
Here is what I have tried (without the search string) and seems to work:
for i in {1..5};do echo $(seq 1 $i); done
The output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
However, when I try this:
for i in {1..5};do sed -i "s/abc/$(seq 1 $i)/g" test; done
I get the following error:
sed: -e expression #1, char 8: unterminated `s' command
sed: -e expression #1, char 8: unterminated `s' command
sed: -e expression #1, char 8: unterminated `s' command
sed: -e expression #1, char 8: unterminated `s' command
I have tried enclosing the replacement string in brackets as well, but it does not seem to work.
The first loop
for i in {1..5}
will be replaced by a glob for filenames within which I want to replace some parameters.