tags:

views:

203

answers:

2

Hello.

I can't seem to understand regular expression at all. How can I match a character which resides between a START and END string. For Example

#START-EDIT

#ValueA=0

#ValueB=1

#END-EDIT

I want to match any # which is between the #START-EDIT and #END-EDIT.

Specifically I want to use sed to replace the matches # values with nothing (delete them) on various files which may or may not have multiple START-EDIT and END-EDIT sections.

+1  A: 

^#START-EDIT.*(#) *. *#END-EDIT$

Ratnesh Maurya
the group (#) matches any occurrence of # and the '*' next to it matches for 0 or more occurrences of the same :) You may play around with '^' at the beginning and '$' at the end according to your requirements.Cheers
Ratnesh Maurya
This should be made non-greedy.
Svante
+1  A: 

sed is line based. you can easily search, replace based on regex in one line. But there is no really easy way to search/replace on multilines. AWK might do the trick.

If you have the regex on one line, the following command could be what you are looking for

sed -e "/^#START-EDIT.*#END-EDIT$//" myInput.txt
Roland