Sed add newline before last occurrence of brace?2019 Community Moderator ElectionHow does the “tail” command's “-f” parameter work?sed: replacing newline at a given line (or last line)Need to insert single quotes in text file for use as SQL query using sedAppend something to each list in a fileReplacing matching text after two matching lineshow to subtract first value from the last one within a column across a row in shell?Add newline character to fileEdit /etc/lvm/lvm.conf and add a new global filterappending into middle of a string using sedUsing sed to replace the last occurrence of character
Are there historical instances of the capital of a colonising country being temporarily or permanently shifted to one of its colonies?
How did Alan Turing break the enigma code using the hint given by the lady in the bar?
Can Mathematica be used to create an Artistic 3D extrusion from a 2D image and wrap a line pattern around it?
Grey hair or white hair
Who deserves to be first and second author? PhD student who collected data, research associate who wrote the paper or supervisor?
Force user to remove USB token
Accepted offer letter, position changed
Why is there a voltage between the mains ground and my radiator?
If one operation is wrong then the whole transaction is wrong
Word for a person who has no opinion about whether god exists
Is this combination of Quivering Palm and Haste RAW?
How did the power source of Mar-Vell's aircraft end up with her?
In the late 1940’s to early 1950’s what technology was available that could melt a LOT of ice?
How can I ensure my trip to the UK will not have to be cancelled because of Brexit?
Single word request: Harming the benefactor
How can I get players to stop ignoring or overlooking the plot hooks I'm giving them?
Distinction between apt-cache and dpkg -l
What may be happening here?
How strictly should I take "Candidates must be local"?
Am I not good enough for you?
htop displays identical program in multiple lines
How are showroom/display vehicles prepared?
They call me Inspector Morse
Accountant/ lawyer will not return my call
Sed add newline before last occurrence of brace?
2019 Community Moderator ElectionHow does the “tail” command's “-f” parameter work?sed: replacing newline at a given line (or last line)Need to insert single quotes in text file for use as SQL query using sedAppend something to each list in a fileReplacing matching text after two matching lineshow to subtract first value from the last one within a column across a row in shell?Add newline character to fileEdit /etc/lvm/lvm.conf and add a new global filterappending into middle of a string using sedUsing sed to replace the last occurrence of character
I want to insert a new line before the last occurrence of brace. My text file looks like that
"accounts":
"0x0000000000000000000000000000000000000008": "builtin": "name": "alt_bn128_pairing", "activate_at": "0x0", "pricing": "alt_bn128_pairing": "base": 100000, "pair": 80000 ,
"0x00Ea169ce7e0992960D3BdE6F5D539C955316432": "balance": "1606938044258990275541962092341162602522202993782792835301376"
So what I want to do is adding a new account through sed script.
Please note that the new account will be specified with a variable, something like:
"$ACCOUNT_ADDR": "balance": "1606938044258990275541962092341162602522202993782792835301376"
shell-script shell sed command-line
New contributor
Stefano De Angelis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I want to insert a new line before the last occurrence of brace. My text file looks like that
"accounts":
"0x0000000000000000000000000000000000000008": "builtin": "name": "alt_bn128_pairing", "activate_at": "0x0", "pricing": "alt_bn128_pairing": "base": 100000, "pair": 80000 ,
"0x00Ea169ce7e0992960D3BdE6F5D539C955316432": "balance": "1606938044258990275541962092341162602522202993782792835301376"
So what I want to do is adding a new account through sed script.
Please note that the new account will be specified with a variable, something like:
"$ACCOUNT_ADDR": "balance": "1606938044258990275541962092341162602522202993782792835301376"
shell-script shell sed command-line
New contributor
Stefano De Angelis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I want to insert a new line before the last occurrence of brace. My text file looks like that
"accounts":
"0x0000000000000000000000000000000000000008": "builtin": "name": "alt_bn128_pairing", "activate_at": "0x0", "pricing": "alt_bn128_pairing": "base": 100000, "pair": 80000 ,
"0x00Ea169ce7e0992960D3BdE6F5D539C955316432": "balance": "1606938044258990275541962092341162602522202993782792835301376"
So what I want to do is adding a new account through sed script.
Please note that the new account will be specified with a variable, something like:
"$ACCOUNT_ADDR": "balance": "1606938044258990275541962092341162602522202993782792835301376"
shell-script shell sed command-line
New contributor
Stefano De Angelis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I want to insert a new line before the last occurrence of brace. My text file looks like that
"accounts":
"0x0000000000000000000000000000000000000008": "builtin": "name": "alt_bn128_pairing", "activate_at": "0x0", "pricing": "alt_bn128_pairing": "base": 100000, "pair": 80000 ,
"0x00Ea169ce7e0992960D3BdE6F5D539C955316432": "balance": "1606938044258990275541962092341162602522202993782792835301376"
So what I want to do is adding a new account through sed script.
Please note that the new account will be specified with a variable, something like:
"$ACCOUNT_ADDR": "balance": "1606938044258990275541962092341162602522202993782792835301376"
shell-script shell sed command-line
shell-script shell sed command-line
New contributor
Stefano De Angelis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Stefano De Angelis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Stefano De Angelis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 1 hour ago
Stefano De AngelisStefano De Angelis
1
1
New contributor
Stefano De Angelis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Stefano De Angelis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Stefano De Angelis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You could add a line after the occurence of "accounts",
sed "/accounts/ a
"$ACCOUNT_ADDR": "balance": "1606938044258990275541962092341162602522202993782792835301376i"
" file
(The " are escaped, to insert variable)
sed "s/^ }$/ "$ACCOUNT_ADDR": "balance": "1606938044258990275541962092341162602522202993782792835301376i" n }/g" file
Will replace your } line and print two lines.
add a comment |
sed is the wrong tool for this job. One of the right tools is jq.
% cat wibble.json
"accounts":
"0x0000000000000000000000000000000000000008": "builtin": "name": "alt_bn128_pairing", "activate_at": "0x0", "pricing": "alt_bn128_pairing": "base": 100000, "pair": 80000 ,
"0x00Ea169ce7e0992960D3BdE6F5D539C955316432": "balance": "1606938044258990275541962092341162602522202993782792835301376"
% ACCOUNT_ADDR="0xdeadbeeffeefdface0badd00dcacad0d0eeeeeeee"
% jq '."accounts"."'"$ACCOUNT_ADDR"'"."balance"="42"' wibble.json
"accounts":
"0x0000000000000000000000000000000000000008":
"builtin":
"name": "alt_bn128_pairing",
"activate_at": "0x0",
"pricing":
"alt_bn128_pairing":
"base": 100000,
"pair": 80000
,
"0x00Ea169ce7e0992960D3BdE6F5D539C955316432":
"balance": "1606938044258990275541962092341162602522202993782792835301376"
,
"0xdeadbeeffeefdface0badd00dcacad0d0eeeeeeee":
"balance": "42"
%
It also caught the fact that you had a key+value pair with no enclosing object. ☺
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Stefano De Angelis is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f505866%2fsed-add-newline-before-last-occurrence-of-brace%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could add a line after the occurence of "accounts",
sed "/accounts/ a
"$ACCOUNT_ADDR": "balance": "1606938044258990275541962092341162602522202993782792835301376i"
" file
(The " are escaped, to insert variable)
sed "s/^ }$/ "$ACCOUNT_ADDR": "balance": "1606938044258990275541962092341162602522202993782792835301376i" n }/g" file
Will replace your } line and print two lines.
add a comment |
You could add a line after the occurence of "accounts",
sed "/accounts/ a
"$ACCOUNT_ADDR": "balance": "1606938044258990275541962092341162602522202993782792835301376i"
" file
(The " are escaped, to insert variable)
sed "s/^ }$/ "$ACCOUNT_ADDR": "balance": "1606938044258990275541962092341162602522202993782792835301376i" n }/g" file
Will replace your } line and print two lines.
add a comment |
You could add a line after the occurence of "accounts",
sed "/accounts/ a
"$ACCOUNT_ADDR": "balance": "1606938044258990275541962092341162602522202993782792835301376i"
" file
(The " are escaped, to insert variable)
sed "s/^ }$/ "$ACCOUNT_ADDR": "balance": "1606938044258990275541962092341162602522202993782792835301376i" n }/g" file
Will replace your } line and print two lines.
You could add a line after the occurence of "accounts",
sed "/accounts/ a
"$ACCOUNT_ADDR": "balance": "1606938044258990275541962092341162602522202993782792835301376i"
" file
(The " are escaped, to insert variable)
sed "s/^ }$/ "$ACCOUNT_ADDR": "balance": "1606938044258990275541962092341162602522202993782792835301376i" n }/g" file
Will replace your } line and print two lines.
answered 1 hour ago
ILikeMatDotHILikeMatDotH
564
564
add a comment |
add a comment |
sed is the wrong tool for this job. One of the right tools is jq.
% cat wibble.json
"accounts":
"0x0000000000000000000000000000000000000008": "builtin": "name": "alt_bn128_pairing", "activate_at": "0x0", "pricing": "alt_bn128_pairing": "base": 100000, "pair": 80000 ,
"0x00Ea169ce7e0992960D3BdE6F5D539C955316432": "balance": "1606938044258990275541962092341162602522202993782792835301376"
% ACCOUNT_ADDR="0xdeadbeeffeefdface0badd00dcacad0d0eeeeeeee"
% jq '."accounts"."'"$ACCOUNT_ADDR"'"."balance"="42"' wibble.json
"accounts":
"0x0000000000000000000000000000000000000008":
"builtin":
"name": "alt_bn128_pairing",
"activate_at": "0x0",
"pricing":
"alt_bn128_pairing":
"base": 100000,
"pair": 80000
,
"0x00Ea169ce7e0992960D3BdE6F5D539C955316432":
"balance": "1606938044258990275541962092341162602522202993782792835301376"
,
"0xdeadbeeffeefdface0badd00dcacad0d0eeeeeeee":
"balance": "42"
%
It also caught the fact that you had a key+value pair with no enclosing object. ☺
add a comment |
sed is the wrong tool for this job. One of the right tools is jq.
% cat wibble.json
"accounts":
"0x0000000000000000000000000000000000000008": "builtin": "name": "alt_bn128_pairing", "activate_at": "0x0", "pricing": "alt_bn128_pairing": "base": 100000, "pair": 80000 ,
"0x00Ea169ce7e0992960D3BdE6F5D539C955316432": "balance": "1606938044258990275541962092341162602522202993782792835301376"
% ACCOUNT_ADDR="0xdeadbeeffeefdface0badd00dcacad0d0eeeeeeee"
% jq '."accounts"."'"$ACCOUNT_ADDR"'"."balance"="42"' wibble.json
"accounts":
"0x0000000000000000000000000000000000000008":
"builtin":
"name": "alt_bn128_pairing",
"activate_at": "0x0",
"pricing":
"alt_bn128_pairing":
"base": 100000,
"pair": 80000
,
"0x00Ea169ce7e0992960D3BdE6F5D539C955316432":
"balance": "1606938044258990275541962092341162602522202993782792835301376"
,
"0xdeadbeeffeefdface0badd00dcacad0d0eeeeeeee":
"balance": "42"
%
It also caught the fact that you had a key+value pair with no enclosing object. ☺
add a comment |
sed is the wrong tool for this job. One of the right tools is jq.
% cat wibble.json
"accounts":
"0x0000000000000000000000000000000000000008": "builtin": "name": "alt_bn128_pairing", "activate_at": "0x0", "pricing": "alt_bn128_pairing": "base": 100000, "pair": 80000 ,
"0x00Ea169ce7e0992960D3BdE6F5D539C955316432": "balance": "1606938044258990275541962092341162602522202993782792835301376"
% ACCOUNT_ADDR="0xdeadbeeffeefdface0badd00dcacad0d0eeeeeeee"
% jq '."accounts"."'"$ACCOUNT_ADDR"'"."balance"="42"' wibble.json
"accounts":
"0x0000000000000000000000000000000000000008":
"builtin":
"name": "alt_bn128_pairing",
"activate_at": "0x0",
"pricing":
"alt_bn128_pairing":
"base": 100000,
"pair": 80000
,
"0x00Ea169ce7e0992960D3BdE6F5D539C955316432":
"balance": "1606938044258990275541962092341162602522202993782792835301376"
,
"0xdeadbeeffeefdface0badd00dcacad0d0eeeeeeee":
"balance": "42"
%
It also caught the fact that you had a key+value pair with no enclosing object. ☺
sed is the wrong tool for this job. One of the right tools is jq.
% cat wibble.json
"accounts":
"0x0000000000000000000000000000000000000008": "builtin": "name": "alt_bn128_pairing", "activate_at": "0x0", "pricing": "alt_bn128_pairing": "base": 100000, "pair": 80000 ,
"0x00Ea169ce7e0992960D3BdE6F5D539C955316432": "balance": "1606938044258990275541962092341162602522202993782792835301376"
% ACCOUNT_ADDR="0xdeadbeeffeefdface0badd00dcacad0d0eeeeeeee"
% jq '."accounts"."'"$ACCOUNT_ADDR"'"."balance"="42"' wibble.json
"accounts":
"0x0000000000000000000000000000000000000008":
"builtin":
"name": "alt_bn128_pairing",
"activate_at": "0x0",
"pricing":
"alt_bn128_pairing":
"base": 100000,
"pair": 80000
,
"0x00Ea169ce7e0992960D3BdE6F5D539C955316432":
"balance": "1606938044258990275541962092341162602522202993782792835301376"
,
"0xdeadbeeffeefdface0badd00dcacad0d0eeeeeeee":
"balance": "42"
%
It also caught the fact that you had a key+value pair with no enclosing object. ☺
answered 54 mins ago
JdeBPJdeBP
36.3k473172
36.3k473172
add a comment |
add a comment |
Stefano De Angelis is a new contributor. Be nice, and check out our Code of Conduct.
Stefano De Angelis is a new contributor. Be nice, and check out our Code of Conduct.
Stefano De Angelis is a new contributor. Be nice, and check out our Code of Conduct.
Stefano De Angelis is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f505866%2fsed-add-newline-before-last-occurrence-of-brace%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
-command-line, sed, shell, shell-script