Using variables in sed -f (where sed script is in a file rather than inline)

前端 未结 5 1045
醉话见心
醉话见心 2021-01-13 03:01

We have a process which can use a file containing sed commands to alter piped input.

I need to replace a placeholder in the input with a variable value,

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-13 04:00

    To add a newline in the replacement expression using a sed file, what finally worked for me is escaping a literal newline. Example: to append a newline after the string NewLineHere, then this worked for me:

    #! /usr/bin/sed -f
    s/NewLineHere/NewLineHere\
    /g
    

    Not sure it matters but I am on Solaris unix, so not GNU sed for sure.

提交回复
热议问题