Skip to main content
added 110 characters in body
Source Link
Zanna
  • 3.7k
  • 1
  • 20
  • 28

In sed you can use a range (stopping on the empty line at the end of the [shovel] category):

sed '/\[shovel\]/,/^$/ s/enabled = 0/enabled = 1/' file

the first part /\[shovel\]/,/^$/ means find a line with [shovel], keep going until you find an empty line, and do the following command(s) (in this case a simple s/old/new) only on that part of file

Note in response to comment: As far as I know, sed will not accept alternative delimiters in ranges and addresses (so escape any / characters that must be literal, if you need to match them), but youunless they are preceded by a backslash. You can stillalways use onean alternative delimiter in any following commands, for example:

sed '/\[shovel\]/,/^$/ s|enabled = 0|enabled = 1|' file

Or

sed '\|\[shovel\]|, |^$| s|enabled = 0|enabled = 1|' file

In sed you can use a range (stopping on the empty line at the end of the [shovel] category):

sed '/\[shovel\]/,/^$/ s/enabled = 0/enabled = 1/' file

the first part /\[shovel\]/,/^$/ means find a line with [shovel], keep going until you find an empty line, and do the following command(s) (in this case a simple s/old/new) only on that part of file

Note in response to comment: As far as I know, sed will not accept alternative delimiters in ranges and addresses (so escape any / characters that must be literal, if you need to match them), but you can still use one in any following commands, for example:

sed '/\[shovel\]/,/^$/ s|enabled = 0|enabled = 1|' file

In sed you can use a range (stopping on the empty line at the end of the [shovel] category):

sed '/\[shovel\]/,/^$/ s/enabled = 0/enabled = 1/' file

the first part /\[shovel\]/,/^$/ means find a line with [shovel], keep going until you find an empty line, and do the following command(s) (in this case a simple s/old/new) only on that part of file

Note in response to comment: sed will not accept alternative delimiters in ranges and addresses (so escape any / characters that must be literal, if you need to match them), unless they are preceded by a backslash. You can always use an alternative delimiter in any following commands, for example:

sed '/\[shovel\]/,/^$/ s|enabled = 0|enabled = 1|' file

Or

sed '\|\[shovel\]|, |^$| s|enabled = 0|enabled = 1|' file
added 328 characters in body
Source Link
Zanna
  • 3.7k
  • 1
  • 20
  • 28

In sed you can use a range (stopping on the empty line at the end of the [shovel] category):

sed '/\[shovel\]/,/^$/ s/enabled = 0/enabled = 1/' file

the first part /\[shovel\]/,/^$/ means find a line with [shovel], keep going until you find an empty line, and do the following command(s) (in this case a simple s/old/new) only on that part of file

Note in response to comment: As far as I know, sed will not accept alternative delimiters in ranges and addresses (so escape any / characters that must be literal, if you need to match them), but you can still use one in any following commands, for example:

sed '/\[shovel\]/,/^$/ s|enabled = 0|enabled = 1|' file

In sed you can use a range (stopping on the empty line at the end of the [shovel] category):

sed '/\[shovel\]/,/^$/ s/enabled = 0/enabled = 1/' file

the first part /\[shovel\]/,/^$/ means find a line with [shovel], keep going until you find an empty line, and do the following command(s) (in this case a simple s/old/new) only on that part of file

In sed you can use a range (stopping on the empty line at the end of the [shovel] category):

sed '/\[shovel\]/,/^$/ s/enabled = 0/enabled = 1/' file

the first part /\[shovel\]/,/^$/ means find a line with [shovel], keep going until you find an empty line, and do the following command(s) (in this case a simple s/old/new) only on that part of file

Note in response to comment: As far as I know, sed will not accept alternative delimiters in ranges and addresses (so escape any / characters that must be literal, if you need to match them), but you can still use one in any following commands, for example:

sed '/\[shovel\]/,/^$/ s|enabled = 0|enabled = 1|' file
Source Link
Zanna
  • 3.7k
  • 1
  • 20
  • 28

In sed you can use a range (stopping on the empty line at the end of the [shovel] category):

sed '/\[shovel\]/,/^$/ s/enabled = 0/enabled = 1/' file

the first part /\[shovel\]/,/^$/ means find a line with [shovel], keep going until you find an empty line, and do the following command(s) (in this case a simple s/old/new) only on that part of file