Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SED delete specific lines between two patterns?

I am trying to filter an *.ics file using sed. The *.ics file looks like this:

[...]

BEGIN:VEVENT
UID:0xfoo
SUMMARY:foo
DTSTART:20131212T090000
DTEND:20131212T100000
SEQUENCE:0
DTSTAMP:20131212T100000
LOCATION:foo
CATEGORIES:foo
DESCRIPTION:foo
CLASS:PUBLIC
END:VEVENT

[...]

I want to delete lines starting e.g. with UID or SEQUENCE, but only if they are between BEGIN:VEVENT and END:VEVENT

I tried to delete these lines with:

sed '/^BEGIN:VEVENT/,/^END:VEVENT/ /^UID/d'

But it will only return an error saying something like unknown command '/'

How is it possible to delete these lines?

Thanks!

like image 454
edloaa Avatar asked Dec 06 '22 05:12

edloaa


1 Answers

try this line:

 sed '/^BEGIN:VEVENT/,/^END:VEVENT/{/^\(UID\|SEQUENCE\)/d}' file
like image 126
Kent Avatar answered Dec 09 '22 13:12

Kent