Use a variable in a sed command

后端 未结 6 1378
梦谈多话
梦谈多话 2020-12-09 03:15

I can\'t seem to use a variable in a sed command, for example:

sed \"24s/.*/\"$ct_tname\"/\" file1.sas > file2.sas

I want $ct_tnam

6条回答
  •  不思量自难忘°
    2020-12-09 03:48

    You need to use double (") quotes, with single (') quotes the value of the variable doesn't get replaced. Since you have double quotes in your replacement text, you need to escape them:

    sed "24s/.*/\"$ct_tname\"/" file1.sas > file2.sas
    

提交回复
热议问题