sed -i -e 'expr1' \ -e 'expr2' <file>
How do I unsee this? Please send help.
Is it that bad?
It doesn't fit my case. I have a file containing placeholder and want to replace that with a multi-line string
It can't possibly be good when done in bash.
Then why do you insert placeholder after the multi-line string?
oh i thought you wanted muliti expression with on sed command
I have an array in a JS file that I need to fill with a long object, so I do something like array: [ PLACEHOLDER ], and then sed -i 's|PLACEHOLDER|${ITEM}PLACEHOLDER|g' file.js for each $ITEM I have to put in the array
Just put them together in bash and then replace once at the end.
That's not the issue. The issue is that in my example $ITEM is a multi-line string, and that bothers sed, it seems
It actually is, and that's what I'm doing alright, right? I have a multi-line string in a variable $ITEM. Do I need to escape the new-lines? If so, how?
i dont know until i see what string those variables contain
This is the real case
If you need to do multiline sed it's time to reconsider using sed
OK, what would you suggest instead?
Looks like JSON, so just use a json parser to redo it.
Unfortunately it's a Javascript file
Can't you just deploy the file in its entirety?
No, the Bash script has to modify the Javascript script at runtime, before the application starts
The only solution would be to write a single line without new-lines characters, but why this works and in my case, where the expressions is a variable with new-lines, doesn't?
Just use perl for multiline, but seriously reconsider if you can't do or push for a proper deploy
Try using envsubst
It's not present in my env. Do you know how to do it with perl maybe?
https://gitlab.com/C0rn3j/arch/blob/703dae958dab40002bf7b9bb85970f0d00d57acd/install.sh#L358
I can't install it in the deployment env 😔 I'll try with perl when I can and see what I can do
Обсуждают сегодня