How to grep 7 lines after match and replace text?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












I'm trying grep 7 lines after match and replace a context in those 7 lines and save it in the same file.



For Example:



<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>


i would like to replace the value of MaxRequestsPerChild with 5000.



I have tried with:



grep "IfModule prefork.c" httpd.conf -A7 | /bin/sed -nE "/bMaxRequestsPerChildb/ s/[0-9]+/50/"


But no luck.







share|improve this question





















  • why not just grep for the string you're looking for in the first place?
    – imabug
    Jun 21 at 9:25






  • 1




    Sorry if I'm a bit daft, but why not just change the line in an editor?
    – Kusalananda
    Jun 21 at 9:25










  • @imabug there are other modules having the same pattern.
    – nkmox k
    Jun 21 at 9:26






  • 2




    there is several problem here, first, you want to edit a file and you do not provide sed with a file name but with stdin. So sed will never work, I suggest you write a script that get line number with grep and then sed inline at the properline number. I will not help you make this logic a oneliner
    – Kiwy
    Jun 21 at 9:28






  • 2




    @nkmoxk You're administrating 73 machines. Are you thinking you would run this over SSH in a loop? Have you considered Ansible?
    – Kusalananda
    Jun 21 at 9:30














up vote
3
down vote

favorite












I'm trying grep 7 lines after match and replace a context in those 7 lines and save it in the same file.



For Example:



<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>


i would like to replace the value of MaxRequestsPerChild with 5000.



I have tried with:



grep "IfModule prefork.c" httpd.conf -A7 | /bin/sed -nE "/bMaxRequestsPerChildb/ s/[0-9]+/50/"


But no luck.







share|improve this question





















  • why not just grep for the string you're looking for in the first place?
    – imabug
    Jun 21 at 9:25






  • 1




    Sorry if I'm a bit daft, but why not just change the line in an editor?
    – Kusalananda
    Jun 21 at 9:25










  • @imabug there are other modules having the same pattern.
    – nkmox k
    Jun 21 at 9:26






  • 2




    there is several problem here, first, you want to edit a file and you do not provide sed with a file name but with stdin. So sed will never work, I suggest you write a script that get line number with grep and then sed inline at the properline number. I will not help you make this logic a oneliner
    – Kiwy
    Jun 21 at 9:28






  • 2




    @nkmoxk You're administrating 73 machines. Are you thinking you would run this over SSH in a loop? Have you considered Ansible?
    – Kusalananda
    Jun 21 at 9:30












up vote
3
down vote

favorite









up vote
3
down vote

favorite











I'm trying grep 7 lines after match and replace a context in those 7 lines and save it in the same file.



For Example:



<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>


i would like to replace the value of MaxRequestsPerChild with 5000.



I have tried with:



grep "IfModule prefork.c" httpd.conf -A7 | /bin/sed -nE "/bMaxRequestsPerChildb/ s/[0-9]+/50/"


But no luck.







share|improve this question













I'm trying grep 7 lines after match and replace a context in those 7 lines and save it in the same file.



For Example:



<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>


i would like to replace the value of MaxRequestsPerChild with 5000.



I have tried with:



grep "IfModule prefork.c" httpd.conf -A7 | /bin/sed -nE "/bMaxRequestsPerChildb/ s/[0-9]+/50/"


But no luck.









share|improve this question












share|improve this question




share|improve this question








edited Jun 21 at 9:23









SivaPrasath

3,90111737




3,90111737









asked Jun 21 at 9:20









nkmox k

186




186











  • why not just grep for the string you're looking for in the first place?
    – imabug
    Jun 21 at 9:25






  • 1




    Sorry if I'm a bit daft, but why not just change the line in an editor?
    – Kusalananda
    Jun 21 at 9:25










  • @imabug there are other modules having the same pattern.
    – nkmox k
    Jun 21 at 9:26






  • 2




    there is several problem here, first, you want to edit a file and you do not provide sed with a file name but with stdin. So sed will never work, I suggest you write a script that get line number with grep and then sed inline at the properline number. I will not help you make this logic a oneliner
    – Kiwy
    Jun 21 at 9:28






  • 2




    @nkmoxk You're administrating 73 machines. Are you thinking you would run this over SSH in a loop? Have you considered Ansible?
    – Kusalananda
    Jun 21 at 9:30
















  • why not just grep for the string you're looking for in the first place?
    – imabug
    Jun 21 at 9:25






  • 1




    Sorry if I'm a bit daft, but why not just change the line in an editor?
    – Kusalananda
    Jun 21 at 9:25










  • @imabug there are other modules having the same pattern.
    – nkmox k
    Jun 21 at 9:26






  • 2




    there is several problem here, first, you want to edit a file and you do not provide sed with a file name but with stdin. So sed will never work, I suggest you write a script that get line number with grep and then sed inline at the properline number. I will not help you make this logic a oneliner
    – Kiwy
    Jun 21 at 9:28






  • 2




    @nkmoxk You're administrating 73 machines. Are you thinking you would run this over SSH in a loop? Have you considered Ansible?
    – Kusalananda
    Jun 21 at 9:30















why not just grep for the string you're looking for in the first place?
– imabug
Jun 21 at 9:25




why not just grep for the string you're looking for in the first place?
– imabug
Jun 21 at 9:25




1




1




Sorry if I'm a bit daft, but why not just change the line in an editor?
– Kusalananda
Jun 21 at 9:25




Sorry if I'm a bit daft, but why not just change the line in an editor?
– Kusalananda
Jun 21 at 9:25












@imabug there are other modules having the same pattern.
– nkmox k
Jun 21 at 9:26




@imabug there are other modules having the same pattern.
– nkmox k
Jun 21 at 9:26




2




2




there is several problem here, first, you want to edit a file and you do not provide sed with a file name but with stdin. So sed will never work, I suggest you write a script that get line number with grep and then sed inline at the properline number. I will not help you make this logic a oneliner
– Kiwy
Jun 21 at 9:28




there is several problem here, first, you want to edit a file and you do not provide sed with a file name but with stdin. So sed will never work, I suggest you write a script that get line number with grep and then sed inline at the properline number. I will not help you make this logic a oneliner
– Kiwy
Jun 21 at 9:28




2




2




@nkmoxk You're administrating 73 machines. Are you thinking you would run this over SSH in a loop? Have you considered Ansible?
– Kusalananda
Jun 21 at 9:30




@nkmoxk You're administrating 73 machines. Are you thinking you would run this over SSH in a loop? Have you considered Ansible?
– Kusalananda
Jun 21 at 9:30










3 Answers
3






active

oldest

votes

















up vote
1
down vote



accepted










Here is a SED solution, hope it will help you.



sed '/<IfModule prefork.c>/,/MaxRequestsPerChild/s/MaxRequestsPerChild.*/MaxRequestsPerChild 5000/' apacheconf


It works by matching the Module name then replacing the next "MaxRequestsPerChild" line with the 5000 value. It will ignore the "MaxRequestsPerChild" of all other modules.



Give it a try.






share|improve this answer

















  • 1




    awesome man!!!!
    – nkmox k
    Jun 21 at 13:28

















up vote
0
down vote













With GNU sed (not sure if syntax/feature is okay for other versions)



To change within 6 lines after matching line:



sed -E '/IfModule prefork.c/N;N;N;N;N;N;s/(MaxRequestsPerChild +)[0-9]+/15000/'


here, N will add a newline to the pattern space, then append the next line of input to the pattern space





If it is always 6th line:



sed -E '/IfModule prefork.c/n;n;n;n;n;n;s/[0-9]+/5000/'


here n will replace the pattern space with the next line of input





Or, simpler syntax with relative addressing



sed -E '/IfModule prefork.c/,+6 s/(MaxRequestsPerChild +)[0-9]+/15000/'





share|improve this answer























  • Thanks, but not getting the result. Looks like problem with [0-9]+
    – nkmox k
    Jun 21 at 10:10










  • @nkmoxk can you give details.. did you get an error? or something else happened? it works for me on GNU sed(you've tagged linux, so I'm assuming you have GNU sed)
    – Sundeep
    Jun 21 at 10:24










  • its not replacing the value. if i remove + sign, it replaces only the first digit as expected.
    – nkmox k
    Jun 21 at 10:27










  • did you use sed -E ? may be your version needs sed -r?
    – Sundeep
    Jun 21 at 10:46

















up vote
0
down vote













You could put sed's range operator , to good use here in case you are indifferent to line numbers:



sed -e '
/<IfModule prefork.c>/,|</IfModule>|!b
H;|</IfModule>|!d;g;s/.//;
s/((n)MaxRequestsPerChild[[:blank:]]1,)[1-9][0-9]*n/150002/
' config-file


  1. Store the range in the hold space.

  2. When the range end is detected, retrieve the range from the hold area, and

  3. Perform the desired substitution.

  4. Lines not falling in the range are left to themselves and passed on to stdout.





share|improve this answer





















  • sed -e ' /<IfModule prefork.c>/,|</IfModule>|!b H;|</IfModule>|!d;g;s/.//; s/((n)MaxRequestsPerChild[[:blank:]]1,)[1-9][0-9]*n/150002/ ' httpd.conf | head -n108 | tail -n1 MaxRequestsPerChild 5000
    – nkmox k
    Jun 21 at 12:18










  • Thanks, but its not substituting.
    – nkmox k
    Jun 21 at 12:19











  • @nkmoxk You cannot write the sed command in one line as you've shown. Give each line of sed code with it's own -e option.
    – Rakesh Sharma
    Jun 22 at 5:33










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',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451053%2fhow-to-grep-7-lines-after-match-and-replace-text%23new-answer', 'question_page');

);

Post as a guest






























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Here is a SED solution, hope it will help you.



sed '/<IfModule prefork.c>/,/MaxRequestsPerChild/s/MaxRequestsPerChild.*/MaxRequestsPerChild 5000/' apacheconf


It works by matching the Module name then replacing the next "MaxRequestsPerChild" line with the 5000 value. It will ignore the "MaxRequestsPerChild" of all other modules.



Give it a try.






share|improve this answer

















  • 1




    awesome man!!!!
    – nkmox k
    Jun 21 at 13:28














up vote
1
down vote



accepted










Here is a SED solution, hope it will help you.



sed '/<IfModule prefork.c>/,/MaxRequestsPerChild/s/MaxRequestsPerChild.*/MaxRequestsPerChild 5000/' apacheconf


It works by matching the Module name then replacing the next "MaxRequestsPerChild" line with the 5000 value. It will ignore the "MaxRequestsPerChild" of all other modules.



Give it a try.






share|improve this answer

















  • 1




    awesome man!!!!
    – nkmox k
    Jun 21 at 13:28












up vote
1
down vote



accepted







up vote
1
down vote



accepted






Here is a SED solution, hope it will help you.



sed '/<IfModule prefork.c>/,/MaxRequestsPerChild/s/MaxRequestsPerChild.*/MaxRequestsPerChild 5000/' apacheconf


It works by matching the Module name then replacing the next "MaxRequestsPerChild" line with the 5000 value. It will ignore the "MaxRequestsPerChild" of all other modules.



Give it a try.






share|improve this answer













Here is a SED solution, hope it will help you.



sed '/<IfModule prefork.c>/,/MaxRequestsPerChild/s/MaxRequestsPerChild.*/MaxRequestsPerChild 5000/' apacheconf


It works by matching the Module name then replacing the next "MaxRequestsPerChild" line with the 5000 value. It will ignore the "MaxRequestsPerChild" of all other modules.



Give it a try.







share|improve this answer













share|improve this answer



share|improve this answer











answered Jun 21 at 13:13









K. Kirilov

514




514







  • 1




    awesome man!!!!
    – nkmox k
    Jun 21 at 13:28












  • 1




    awesome man!!!!
    – nkmox k
    Jun 21 at 13:28







1




1




awesome man!!!!
– nkmox k
Jun 21 at 13:28




awesome man!!!!
– nkmox k
Jun 21 at 13:28












up vote
0
down vote













With GNU sed (not sure if syntax/feature is okay for other versions)



To change within 6 lines after matching line:



sed -E '/IfModule prefork.c/N;N;N;N;N;N;s/(MaxRequestsPerChild +)[0-9]+/15000/'


here, N will add a newline to the pattern space, then append the next line of input to the pattern space





If it is always 6th line:



sed -E '/IfModule prefork.c/n;n;n;n;n;n;s/[0-9]+/5000/'


here n will replace the pattern space with the next line of input





Or, simpler syntax with relative addressing



sed -E '/IfModule prefork.c/,+6 s/(MaxRequestsPerChild +)[0-9]+/15000/'





share|improve this answer























  • Thanks, but not getting the result. Looks like problem with [0-9]+
    – nkmox k
    Jun 21 at 10:10










  • @nkmoxk can you give details.. did you get an error? or something else happened? it works for me on GNU sed(you've tagged linux, so I'm assuming you have GNU sed)
    – Sundeep
    Jun 21 at 10:24










  • its not replacing the value. if i remove + sign, it replaces only the first digit as expected.
    – nkmox k
    Jun 21 at 10:27










  • did you use sed -E ? may be your version needs sed -r?
    – Sundeep
    Jun 21 at 10:46














up vote
0
down vote













With GNU sed (not sure if syntax/feature is okay for other versions)



To change within 6 lines after matching line:



sed -E '/IfModule prefork.c/N;N;N;N;N;N;s/(MaxRequestsPerChild +)[0-9]+/15000/'


here, N will add a newline to the pattern space, then append the next line of input to the pattern space





If it is always 6th line:



sed -E '/IfModule prefork.c/n;n;n;n;n;n;s/[0-9]+/5000/'


here n will replace the pattern space with the next line of input





Or, simpler syntax with relative addressing



sed -E '/IfModule prefork.c/,+6 s/(MaxRequestsPerChild +)[0-9]+/15000/'





share|improve this answer























  • Thanks, but not getting the result. Looks like problem with [0-9]+
    – nkmox k
    Jun 21 at 10:10










  • @nkmoxk can you give details.. did you get an error? or something else happened? it works for me on GNU sed(you've tagged linux, so I'm assuming you have GNU sed)
    – Sundeep
    Jun 21 at 10:24










  • its not replacing the value. if i remove + sign, it replaces only the first digit as expected.
    – nkmox k
    Jun 21 at 10:27










  • did you use sed -E ? may be your version needs sed -r?
    – Sundeep
    Jun 21 at 10:46












up vote
0
down vote










up vote
0
down vote









With GNU sed (not sure if syntax/feature is okay for other versions)



To change within 6 lines after matching line:



sed -E '/IfModule prefork.c/N;N;N;N;N;N;s/(MaxRequestsPerChild +)[0-9]+/15000/'


here, N will add a newline to the pattern space, then append the next line of input to the pattern space





If it is always 6th line:



sed -E '/IfModule prefork.c/n;n;n;n;n;n;s/[0-9]+/5000/'


here n will replace the pattern space with the next line of input





Or, simpler syntax with relative addressing



sed -E '/IfModule prefork.c/,+6 s/(MaxRequestsPerChild +)[0-9]+/15000/'





share|improve this answer















With GNU sed (not sure if syntax/feature is okay for other versions)



To change within 6 lines after matching line:



sed -E '/IfModule prefork.c/N;N;N;N;N;N;s/(MaxRequestsPerChild +)[0-9]+/15000/'


here, N will add a newline to the pattern space, then append the next line of input to the pattern space





If it is always 6th line:



sed -E '/IfModule prefork.c/n;n;n;n;n;n;s/[0-9]+/5000/'


here n will replace the pattern space with the next line of input





Or, simpler syntax with relative addressing



sed -E '/IfModule prefork.c/,+6 s/(MaxRequestsPerChild +)[0-9]+/15000/'






share|improve this answer















share|improve this answer



share|improve this answer








edited Jun 21 at 10:06


























answered Jun 21 at 10:00









Sundeep

6,9511826




6,9511826











  • Thanks, but not getting the result. Looks like problem with [0-9]+
    – nkmox k
    Jun 21 at 10:10










  • @nkmoxk can you give details.. did you get an error? or something else happened? it works for me on GNU sed(you've tagged linux, so I'm assuming you have GNU sed)
    – Sundeep
    Jun 21 at 10:24










  • its not replacing the value. if i remove + sign, it replaces only the first digit as expected.
    – nkmox k
    Jun 21 at 10:27










  • did you use sed -E ? may be your version needs sed -r?
    – Sundeep
    Jun 21 at 10:46
















  • Thanks, but not getting the result. Looks like problem with [0-9]+
    – nkmox k
    Jun 21 at 10:10










  • @nkmoxk can you give details.. did you get an error? or something else happened? it works for me on GNU sed(you've tagged linux, so I'm assuming you have GNU sed)
    – Sundeep
    Jun 21 at 10:24










  • its not replacing the value. if i remove + sign, it replaces only the first digit as expected.
    – nkmox k
    Jun 21 at 10:27










  • did you use sed -E ? may be your version needs sed -r?
    – Sundeep
    Jun 21 at 10:46















Thanks, but not getting the result. Looks like problem with [0-9]+
– nkmox k
Jun 21 at 10:10




Thanks, but not getting the result. Looks like problem with [0-9]+
– nkmox k
Jun 21 at 10:10












@nkmoxk can you give details.. did you get an error? or something else happened? it works for me on GNU sed(you've tagged linux, so I'm assuming you have GNU sed)
– Sundeep
Jun 21 at 10:24




@nkmoxk can you give details.. did you get an error? or something else happened? it works for me on GNU sed(you've tagged linux, so I'm assuming you have GNU sed)
– Sundeep
Jun 21 at 10:24












its not replacing the value. if i remove + sign, it replaces only the first digit as expected.
– nkmox k
Jun 21 at 10:27




its not replacing the value. if i remove + sign, it replaces only the first digit as expected.
– nkmox k
Jun 21 at 10:27












did you use sed -E ? may be your version needs sed -r?
– Sundeep
Jun 21 at 10:46




did you use sed -E ? may be your version needs sed -r?
– Sundeep
Jun 21 at 10:46










up vote
0
down vote













You could put sed's range operator , to good use here in case you are indifferent to line numbers:



sed -e '
/<IfModule prefork.c>/,|</IfModule>|!b
H;|</IfModule>|!d;g;s/.//;
s/((n)MaxRequestsPerChild[[:blank:]]1,)[1-9][0-9]*n/150002/
' config-file


  1. Store the range in the hold space.

  2. When the range end is detected, retrieve the range from the hold area, and

  3. Perform the desired substitution.

  4. Lines not falling in the range are left to themselves and passed on to stdout.





share|improve this answer





















  • sed -e ' /<IfModule prefork.c>/,|</IfModule>|!b H;|</IfModule>|!d;g;s/.//; s/((n)MaxRequestsPerChild[[:blank:]]1,)[1-9][0-9]*n/150002/ ' httpd.conf | head -n108 | tail -n1 MaxRequestsPerChild 5000
    – nkmox k
    Jun 21 at 12:18










  • Thanks, but its not substituting.
    – nkmox k
    Jun 21 at 12:19











  • @nkmoxk You cannot write the sed command in one line as you've shown. Give each line of sed code with it's own -e option.
    – Rakesh Sharma
    Jun 22 at 5:33














up vote
0
down vote













You could put sed's range operator , to good use here in case you are indifferent to line numbers:



sed -e '
/<IfModule prefork.c>/,|</IfModule>|!b
H;|</IfModule>|!d;g;s/.//;
s/((n)MaxRequestsPerChild[[:blank:]]1,)[1-9][0-9]*n/150002/
' config-file


  1. Store the range in the hold space.

  2. When the range end is detected, retrieve the range from the hold area, and

  3. Perform the desired substitution.

  4. Lines not falling in the range are left to themselves and passed on to stdout.





share|improve this answer





















  • sed -e ' /<IfModule prefork.c>/,|</IfModule>|!b H;|</IfModule>|!d;g;s/.//; s/((n)MaxRequestsPerChild[[:blank:]]1,)[1-9][0-9]*n/150002/ ' httpd.conf | head -n108 | tail -n1 MaxRequestsPerChild 5000
    – nkmox k
    Jun 21 at 12:18










  • Thanks, but its not substituting.
    – nkmox k
    Jun 21 at 12:19











  • @nkmoxk You cannot write the sed command in one line as you've shown. Give each line of sed code with it's own -e option.
    – Rakesh Sharma
    Jun 22 at 5:33












up vote
0
down vote










up vote
0
down vote









You could put sed's range operator , to good use here in case you are indifferent to line numbers:



sed -e '
/<IfModule prefork.c>/,|</IfModule>|!b
H;|</IfModule>|!d;g;s/.//;
s/((n)MaxRequestsPerChild[[:blank:]]1,)[1-9][0-9]*n/150002/
' config-file


  1. Store the range in the hold space.

  2. When the range end is detected, retrieve the range from the hold area, and

  3. Perform the desired substitution.

  4. Lines not falling in the range are left to themselves and passed on to stdout.





share|improve this answer













You could put sed's range operator , to good use here in case you are indifferent to line numbers:



sed -e '
/<IfModule prefork.c>/,|</IfModule>|!b
H;|</IfModule>|!d;g;s/.//;
s/((n)MaxRequestsPerChild[[:blank:]]1,)[1-9][0-9]*n/150002/
' config-file


  1. Store the range in the hold space.

  2. When the range end is detected, retrieve the range from the hold area, and

  3. Perform the desired substitution.

  4. Lines not falling in the range are left to themselves and passed on to stdout.






share|improve this answer













share|improve this answer



share|improve this answer











answered Jun 21 at 11:09









Rakesh Sharma

3683




3683











  • sed -e ' /<IfModule prefork.c>/,|</IfModule>|!b H;|</IfModule>|!d;g;s/.//; s/((n)MaxRequestsPerChild[[:blank:]]1,)[1-9][0-9]*n/150002/ ' httpd.conf | head -n108 | tail -n1 MaxRequestsPerChild 5000
    – nkmox k
    Jun 21 at 12:18










  • Thanks, but its not substituting.
    – nkmox k
    Jun 21 at 12:19











  • @nkmoxk You cannot write the sed command in one line as you've shown. Give each line of sed code with it's own -e option.
    – Rakesh Sharma
    Jun 22 at 5:33
















  • sed -e ' /<IfModule prefork.c>/,|</IfModule>|!b H;|</IfModule>|!d;g;s/.//; s/((n)MaxRequestsPerChild[[:blank:]]1,)[1-9][0-9]*n/150002/ ' httpd.conf | head -n108 | tail -n1 MaxRequestsPerChild 5000
    – nkmox k
    Jun 21 at 12:18










  • Thanks, but its not substituting.
    – nkmox k
    Jun 21 at 12:19











  • @nkmoxk You cannot write the sed command in one line as you've shown. Give each line of sed code with it's own -e option.
    – Rakesh Sharma
    Jun 22 at 5:33















sed -e ' /<IfModule prefork.c>/,|</IfModule>|!b H;|</IfModule>|!d;g;s/.//; s/((n)MaxRequestsPerChild[[:blank:]]1,)[1-9][0-9]*n/150002/ ' httpd.conf | head -n108 | tail -n1 MaxRequestsPerChild 5000
– nkmox k
Jun 21 at 12:18




sed -e ' /<IfModule prefork.c>/,|</IfModule>|!b H;|</IfModule>|!d;g;s/.//; s/((n)MaxRequestsPerChild[[:blank:]]1,)[1-9][0-9]*n/150002/ ' httpd.conf | head -n108 | tail -n1 MaxRequestsPerChild 5000
– nkmox k
Jun 21 at 12:18












Thanks, but its not substituting.
– nkmox k
Jun 21 at 12:19





Thanks, but its not substituting.
– nkmox k
Jun 21 at 12:19













@nkmoxk You cannot write the sed command in one line as you've shown. Give each line of sed code with it's own -e option.
– Rakesh Sharma
Jun 22 at 5:33




@nkmoxk You cannot write the sed command in one line as you've shown. Give each line of sed code with it's own -e option.
– Rakesh Sharma
Jun 22 at 5:33












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451053%2fhow-to-grep-7-lines-after-match-and-replace-text%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?