variable in sed

后端 未结 1 1759
生来不讨喜
生来不讨喜 2020-12-11 11:12

how can I use a variable as a pattern finder for sed? for example:

sed -i \'/$pc/ s/off/on/\' ~/Documents/Mantenimiento

I know there is a

相关标签:
1条回答
  • 2020-12-11 11:54

    Use double quotes instead of single quotes, or close the quotes just before the variable and reopen them just after.

    sed -i "/$pc/ s/off/on/"
    sed -i '/'$pc'/ s/off/on/'
    

    This will let bash perform the variable evaluation normally.

    0 讨论(0)
提交回复
热议问题