1

I have based my script on the following quesstion Find and replace text within a file using commands

I have a lot of files named test_xxx_01.sql in which i need to replace a text testoriginal with testoriginal_xxx so I wrote the following command

for i in {220,630,1000}; do sed -i 's/testoriginal/testoriginal_\$\{i\}/g' test_${i}_01.sql; done

the expected output is that in the file test_221_01.sql, i should now have 'testoriginal_221'.

but instead i have testoriginal_${i}

how can i fix this command?

Anand
  • 111
  • 4
  • 5
    It's basically a matter of using the right quotes - but be careful of metacharacters. See [How can I use variables in the LHS and RHS of a sed substitution?](https://unix.stackexchange.com/questions/69112/how-can-i-use-variables-in-the-lhs-and-rhs-of-a-sed-substitution) – steeldriver Apr 05 '19 at 12:06
  • 1
    You need to use double quotes for the expression. – pa4080 Apr 05 '19 at 12:12

0 Answers0