0

I am trying to write a sed command like below

i=20
sed 's/./&\
 \/\/this comment has been automatically added using code and identifying function start\
  /$i' zero.swift > out.swift

However, I'm not able to use $i in the last line. I would have expected it to replace $i with 20 and then run the sed command.

However, when I run the above, I get

"s/./&\ \/\/this commen ...": bad flag in substitute command: '$' as error. How should I use the variable in my sed command.

I've read other posts on Stackoverflow, which are not helping me

prabodhprakash
  • 3,825
  • 24
  • 48
  • You need double quotes. I'm pretty sure almost every question on how to use vars in sed say that... – 123 Dec 06 '16 at 09:11
  • are you suggesting , ```sed 's/./&\ \/\/this comment has been automatically added using code and identifying function start\ /"$i"' zero.swift > out.swift``` – prabodhprakash Dec 06 '16 at 09:12
  • No, replace the single quotes with double, and learn how shell quoting works. – 123 Dec 06 '16 at 09:13
  • that works. Could you please post this as answer for me to accept and also, if you could please post some link for quotes in shell, that would be helpful reading. – prabodhprakash Dec 06 '16 at 09:13

0 Answers0