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

前端 未结 5 1056
醉话见心
醉话见心 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 03:38

    I am in agreement with sputnick. I don't believe that sed would be able to complete that task.

    However, you could generate that file on the fly.

    You could change the date to a fixed string, like __DAYOFWEEK__.

    Create a temp file, use sed to replace __DAYOFWEEK__ with $(date +%Y).

    Then parse your file with sed -f $TEMPFILE.

    sed is great, but it might be time to use something like perl that can generate the date on the fly.

提交回复
热议问题