4

File looks like this:

[section1]
a=something
[section_name2]
a=something
[section3]
a=something

How do I replace a=someother only in section_name2?

1 Answer 1

3

Use an address range:

sed '/\[section_name2\]/,/^\[/ s/a=something/a=someother/'
3
  • Thanks alot. Changed it to sed '/[section]/,/^[/ s/a=.*/a=someother/' and it working now
    – arheops
    Sep 11, 2013 at 20:38
  • 1
    @arheops: Not sure how your changed command would have worked. First you are not escaping the [ and ]. Your first pattern /[section]/ will match any line which has one of s,e,c,t,i,o,n in it. Second you are using section instead of section_name2. I don't understand how that would work too.
    – jaychris
    Sep 11, 2013 at 22:46
  • All is working ok. Parser on this site remove escapes.
    – arheops
    Sep 12, 2013 at 0:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .