0

This question already has an answer here:

I've a JSON property which needs to be updated with base64. The flow is:

prop_val=`base64 --wrap=0 < $prop_txt`
sed -i 's@"property_specific": ""@"property_specific": "'"${prop_val}"'"@g' $final_json

It errors out with: line 22: /bin/sed: Argument list too long

The base64 string (single line) is very long. How else can I update the property w/o sed?

Note: the double quotes in format.

Update:

  • Created place holder unique string, to remove double quotes complexity.
  • Tried sed -f; didn't work.

Tried:

     sed -i -f - $final_json << EOF; 's@placeHolder123456@'"${prop_val}"'@g'; EOF

Error:

line 27: warning: here-document at line 23 delimited by end-of-file (wanted `EOF')
line 28: syntax error: unexpected end of file

Tried placing it in a function to avoid EOF error, but it didnt work. Function:

update_prop_specific() {
    sed -i -f - $1 << EOF
    s@placeHolder123456@$2@g
    EOF
}

Suggestions?

marked as duplicate by ilkkachu, Jeff Schaller, peterh, Stephen Rauch, G-Man Dec 4 '17 at 1:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • This answer might help you: Replace a long string with the sed command: Argument list too long error – PesaThe Dec 3 '17 at 19:46
  • @PesaThe thank you, I saw that. Here I need it to be in the same line between double quotes. It’s a good breadcrumb though. – Simply_Me Dec 3 '17 at 19:49
  • @Simply_Me, the sed -f - <<EOF solution should still work, I don't think the double quotes should make a difference with that – ilkkachu Dec 3 '17 at 19:51
  • @ilkkachu interesting, I’ll give it a try shortly. – Simply_Me Dec 3 '17 at 19:53
  • @ilkkachu I tried it, but it errors out (see update). – Simply_Me Dec 3 '17 at 20:38
-1

ended up setting up another file with sed -i -f .... and calling it from the main script, since function and explicit calls cause unexpected EOF

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