0

I am new to shell scripting and working on script. In which I need to create a html report and attach this html report content in json request filed.Then we are using that request to call an API.

I have Json request as Template in the template have a place holder called CONTENT in which I have to replace generated HTML content after encode it using base64.

When I try to add the encoded string in my template using both AWK and sed im getting Argument list is too long error. As my generated HTML file is having 40K lines.

With below approaches I am getting same error.

encStr="$(cat ./myreport.html | base64)"
#AWK-Approach

awk -v var="$encStr" '{gsub("CONTENT", var, $0); print}' /path/totemplate > output.tmp

#SED-Approach

sed -i "s|CONTENT|$encStr|" output.tmp

There is a suggestion to change sed to ed and put the commands in separate file. As per https://unix.stackexchange.com/a/284188/149867 but when I create a seprate .sh file and include it in my current script its not working. Any detailed example for this approach or any other approach.

  • Write the base64 output to a temporary file and include it in the output with the r command of sed (using the place holder pattern as address) – Philippos Oct 15 '19 at 19:52
0

If CONTENT is on its own line then put your replacement into a file tmp and then use

sed -e '/CONTENT/r tmp' -e '/CONTENT/d' inp

which first inserts the contents of the filetmp after your match and then deletes the line with CONTENT

(the answer in @philippos comment doesn't work for me, the file has to be injected after a match and then the match deleted)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.