Re: Delete only the nth block of text, multi-line

"[email protected] [sed-users]" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
I made one minor change (added \n to the regular expression) to Davide's solution, to make the script get rid of an extra line that was showing up in the output. This assumes you are using GNU sed, other sed versions might not recognize \n in the regular expression.
 

 Daniel
 

 $ cat in
foo
[
  aaa 1
  bbb 1
  ccc 1
]
[
  ccc 2
  bbb 2
  aaa 2
]
[
  bbb 3
  ccc 3
  aaa 3
]
[
  bbb 4
  aaa 4
  ccc 4
]
bar
 

 $ cat sed.txt
:loop $!{ N; b loop } # accumulate
s/\[[^]]*\]\n//3 # delete
 

 $ sed -f sed.txt in
foo
[
  aaa 1
  bbb 1
  ccc 1
]
[
  ccc 2
  bbb 2
  aaa 2
]
[
  bbb 4
  aaa 4
  ccc 4
]
bar


 




[Non-text portions of this message have been removed]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.