Edit a file in /etc using shell scripting?
Clash Royale CLAN TAG#URR8PPP
How do I use sed
to edit the file /etc/heat/heat.conf
?
I want to add the new lines under the default section
[DEFAULT]
rabbit_host =controller
rabbit_password =RABBIT_PASS
shell-script sed
add a comment |
How do I use sed
to edit the file /etc/heat/heat.conf
?
I want to add the new lines under the default section
[DEFAULT]
rabbit_host =controller
rabbit_password =RABBIT_PASS
shell-script sed
2
Research and Try yourself before asking
– Tejas
Oct 7 '14 at 10:28
2
Is this a task you got at school?
– gena2x
Oct 7 '14 at 10:49
what exactly do you want to change and why? what is "heat"?
– rubo77
Oct 8 '14 at 16:26
add a comment |
How do I use sed
to edit the file /etc/heat/heat.conf
?
I want to add the new lines under the default section
[DEFAULT]
rabbit_host =controller
rabbit_password =RABBIT_PASS
shell-script sed
How do I use sed
to edit the file /etc/heat/heat.conf
?
I want to add the new lines under the default section
[DEFAULT]
rabbit_host =controller
rabbit_password =RABBIT_PASS
shell-script sed
shell-script sed
edited Oct 8 '14 at 18:58
Michael Mrozek♦
61k29189210
61k29189210
asked Oct 7 '14 at 10:24
bpamzbpamz
26113
26113
2
Research and Try yourself before asking
– Tejas
Oct 7 '14 at 10:28
2
Is this a task you got at school?
– gena2x
Oct 7 '14 at 10:49
what exactly do you want to change and why? what is "heat"?
– rubo77
Oct 8 '14 at 16:26
add a comment |
2
Research and Try yourself before asking
– Tejas
Oct 7 '14 at 10:28
2
Is this a task you got at school?
– gena2x
Oct 7 '14 at 10:49
what exactly do you want to change and why? what is "heat"?
– rubo77
Oct 8 '14 at 16:26
2
2
Research and Try yourself before asking
– Tejas
Oct 7 '14 at 10:28
Research and Try yourself before asking
– Tejas
Oct 7 '14 at 10:28
2
2
Is this a task you got at school?
– gena2x
Oct 7 '14 at 10:49
Is this a task you got at school?
– gena2x
Oct 7 '14 at 10:49
what exactly do you want to change and why? what is "heat"?
– rubo77
Oct 8 '14 at 16:26
what exactly do you want to change and why? what is "heat"?
– rubo77
Oct 8 '14 at 16:26
add a comment |
4 Answers
4
active
oldest
votes
You can use a /regexp/
address to find the line containing [DEFAULT]
, and then an append (a
) command to add lines under it. Pass -i
to sed
to have it modify the file in-place (you might want to run without it first to make sure it's doing the right thing; it will output what the changed file will look like without actually changing it):
# sed -i '/^[DEFAULT]$/a rabbit_host =controllernrabbit_password =RABBIT_PASS' /etc/heat/heat.conf
add a comment |
if you have a file /tmp/a
with the contnet
hello my friend
You can use sed to replace strings:
sed -i 's/hello/hi/g' /tmp/a
this will result in:
hi my friend
see: man sed
Also you can add lines without sed
to a file by using >>
:
echo "I like you">>/tmp/a
Butecho "I like you">>/tmp/a
. It will not replace anything , It just append new thing
– SuperKrish
Nov 7 '16 at 14:25
Yes, like i said ;-)
– rubo77
Nov 7 '16 at 14:32
add a comment |
I am sure the requester has found a solution by now but just in case.
This request is ideal for application crudini
it is available for all the major linux dustibutions
for example the following will add a line to DEFAULT
section of /etc/heat/heat.conf
crudini --set /etc/heat/heat.conf DEFAULT mysetting true
The section:
[DEFAULT]
rabbit_host =controller
rabbit_password =RABBIT_PASS
mysetting = true
will update if entry already in conf file.
add a comment |
Old school ed
approach
ed -s test <<EOF
/^[DEFAULT]$/
a
rabbit_host =controller
rabbit_password =RABBIT_PASS
.
w
q
EOF
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
);
);
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%2f159779%2fedit-a-file-in-etc-using-shell-scripting%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use a /regexp/
address to find the line containing [DEFAULT]
, and then an append (a
) command to add lines under it. Pass -i
to sed
to have it modify the file in-place (you might want to run without it first to make sure it's doing the right thing; it will output what the changed file will look like without actually changing it):
# sed -i '/^[DEFAULT]$/a rabbit_host =controllernrabbit_password =RABBIT_PASS' /etc/heat/heat.conf
add a comment |
You can use a /regexp/
address to find the line containing [DEFAULT]
, and then an append (a
) command to add lines under it. Pass -i
to sed
to have it modify the file in-place (you might want to run without it first to make sure it's doing the right thing; it will output what the changed file will look like without actually changing it):
# sed -i '/^[DEFAULT]$/a rabbit_host =controllernrabbit_password =RABBIT_PASS' /etc/heat/heat.conf
add a comment |
You can use a /regexp/
address to find the line containing [DEFAULT]
, and then an append (a
) command to add lines under it. Pass -i
to sed
to have it modify the file in-place (you might want to run without it first to make sure it's doing the right thing; it will output what the changed file will look like without actually changing it):
# sed -i '/^[DEFAULT]$/a rabbit_host =controllernrabbit_password =RABBIT_PASS' /etc/heat/heat.conf
You can use a /regexp/
address to find the line containing [DEFAULT]
, and then an append (a
) command to add lines under it. Pass -i
to sed
to have it modify the file in-place (you might want to run without it first to make sure it's doing the right thing; it will output what the changed file will look like without actually changing it):
# sed -i '/^[DEFAULT]$/a rabbit_host =controllernrabbit_password =RABBIT_PASS' /etc/heat/heat.conf
edited Oct 8 '14 at 21:53
answered Oct 8 '14 at 19:00
Michael Mrozek♦Michael Mrozek
61k29189210
61k29189210
add a comment |
add a comment |
if you have a file /tmp/a
with the contnet
hello my friend
You can use sed to replace strings:
sed -i 's/hello/hi/g' /tmp/a
this will result in:
hi my friend
see: man sed
Also you can add lines without sed
to a file by using >>
:
echo "I like you">>/tmp/a
Butecho "I like you">>/tmp/a
. It will not replace anything , It just append new thing
– SuperKrish
Nov 7 '16 at 14:25
Yes, like i said ;-)
– rubo77
Nov 7 '16 at 14:32
add a comment |
if you have a file /tmp/a
with the contnet
hello my friend
You can use sed to replace strings:
sed -i 's/hello/hi/g' /tmp/a
this will result in:
hi my friend
see: man sed
Also you can add lines without sed
to a file by using >>
:
echo "I like you">>/tmp/a
Butecho "I like you">>/tmp/a
. It will not replace anything , It just append new thing
– SuperKrish
Nov 7 '16 at 14:25
Yes, like i said ;-)
– rubo77
Nov 7 '16 at 14:32
add a comment |
if you have a file /tmp/a
with the contnet
hello my friend
You can use sed to replace strings:
sed -i 's/hello/hi/g' /tmp/a
this will result in:
hi my friend
see: man sed
Also you can add lines without sed
to a file by using >>
:
echo "I like you">>/tmp/a
if you have a file /tmp/a
with the contnet
hello my friend
You can use sed to replace strings:
sed -i 's/hello/hi/g' /tmp/a
this will result in:
hi my friend
see: man sed
Also you can add lines without sed
to a file by using >>
:
echo "I like you">>/tmp/a
answered Oct 8 '14 at 16:23
rubo77rubo77
7,5772572133
7,5772572133
Butecho "I like you">>/tmp/a
. It will not replace anything , It just append new thing
– SuperKrish
Nov 7 '16 at 14:25
Yes, like i said ;-)
– rubo77
Nov 7 '16 at 14:32
add a comment |
Butecho "I like you">>/tmp/a
. It will not replace anything , It just append new thing
– SuperKrish
Nov 7 '16 at 14:25
Yes, like i said ;-)
– rubo77
Nov 7 '16 at 14:32
But
echo "I like you">>/tmp/a
. It will not replace anything , It just append new thing– SuperKrish
Nov 7 '16 at 14:25
But
echo "I like you">>/tmp/a
. It will not replace anything , It just append new thing– SuperKrish
Nov 7 '16 at 14:25
Yes, like i said ;-)
– rubo77
Nov 7 '16 at 14:32
Yes, like i said ;-)
– rubo77
Nov 7 '16 at 14:32
add a comment |
I am sure the requester has found a solution by now but just in case.
This request is ideal for application crudini
it is available for all the major linux dustibutions
for example the following will add a line to DEFAULT
section of /etc/heat/heat.conf
crudini --set /etc/heat/heat.conf DEFAULT mysetting true
The section:
[DEFAULT]
rabbit_host =controller
rabbit_password =RABBIT_PASS
mysetting = true
will update if entry already in conf file.
add a comment |
I am sure the requester has found a solution by now but just in case.
This request is ideal for application crudini
it is available for all the major linux dustibutions
for example the following will add a line to DEFAULT
section of /etc/heat/heat.conf
crudini --set /etc/heat/heat.conf DEFAULT mysetting true
The section:
[DEFAULT]
rabbit_host =controller
rabbit_password =RABBIT_PASS
mysetting = true
will update if entry already in conf file.
add a comment |
I am sure the requester has found a solution by now but just in case.
This request is ideal for application crudini
it is available for all the major linux dustibutions
for example the following will add a line to DEFAULT
section of /etc/heat/heat.conf
crudini --set /etc/heat/heat.conf DEFAULT mysetting true
The section:
[DEFAULT]
rabbit_host =controller
rabbit_password =RABBIT_PASS
mysetting = true
will update if entry already in conf file.
I am sure the requester has found a solution by now but just in case.
This request is ideal for application crudini
it is available for all the major linux dustibutions
for example the following will add a line to DEFAULT
section of /etc/heat/heat.conf
crudini --set /etc/heat/heat.conf DEFAULT mysetting true
The section:
[DEFAULT]
rabbit_host =controller
rabbit_password =RABBIT_PASS
mysetting = true
will update if entry already in conf file.
edited Jan 10 at 19:52
Marco
774616
774616
answered Jan 10 at 12:44
IT Support GUYIT Support GUY
1
1
add a comment |
add a comment |
Old school ed
approach
ed -s test <<EOF
/^[DEFAULT]$/
a
rabbit_host =controller
rabbit_password =RABBIT_PASS
.
w
q
EOF
add a comment |
Old school ed
approach
ed -s test <<EOF
/^[DEFAULT]$/
a
rabbit_host =controller
rabbit_password =RABBIT_PASS
.
w
q
EOF
add a comment |
Old school ed
approach
ed -s test <<EOF
/^[DEFAULT]$/
a
rabbit_host =controller
rabbit_password =RABBIT_PASS
.
w
q
EOF
Old school ed
approach
ed -s test <<EOF
/^[DEFAULT]$/
a
rabbit_host =controller
rabbit_password =RABBIT_PASS
.
w
q
EOF
answered Jan 10 at 20:00
stevesteve
14k22452
14k22452
add a comment |
add a comment |
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%2f159779%2fedit-a-file-in-etc-using-shell-scripting%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
2
Research and Try yourself before asking
– Tejas
Oct 7 '14 at 10:28
2
Is this a task you got at school?
– gena2x
Oct 7 '14 at 10:49
what exactly do you want to change and why? what is "heat"?
– rubo77
Oct 8 '14 at 16:26