Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] sed - delete substring between two matches?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
imanassypov
Tux's lil' helper
Tux's lil' helper


Joined: 08 Dec 2005
Posts: 118
Location: Toronto, Canada

PostPosted: Tue Nov 08, 2011 4:09 pm    Post subject: [SOLVED] sed - delete substring between two matches? Reply with quote

Hi,

I have files containing strings such as

Code:

one two thee MARK1 4 five 6 MARK2 etc etc
etc etc etc


I would like to remove everything between and including 'MARK1' and 'MARK2', so the output would read

Code:

one two thee  etc etc
etc etc etc


Whats the optimal way to achieve this with sed?

I tried this, but it blanks all files:

Code:

sed -i '/MARK1/,/MARK2/d' *.txt
[code]

I believe the above command matches the whole line rather than the range exactly...

Thanks![/code]

_________________
I.M.


Last edited by imanassypov on Tue Nov 08, 2011 10:47 pm; edited 1 time in total
Back to top
View user's profile Send private message
tomk
Bodhisattva
Bodhisattva


Joined: 23 Sep 2003
Posts: 7221
Location: Sat in front of my computer

PostPosted: Tue Nov 08, 2011 4:19 pm    Post subject: Reply with quote

Something like this:

Code:
sed -i -e "s/MARK1.*MARK2//g" filename

_________________
Search | Read | Answer | Report | Strip
Back to top
View user's profile Send private message
imanassypov
Tux's lil' helper
Tux's lil' helper


Joined: 08 Dec 2005
Posts: 118
Location: Toronto, Canada

PostPosted: Tue Nov 08, 2011 8:13 pm    Post subject: Reply with quote

Thanks, that works!

-whats the reason the command I tried did not work?
_________________
I.M.
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10589
Location: Somewhere over Atlanta, Georgia

PostPosted: Tue Nov 08, 2011 8:18 pm    Post subject: Reply with quote

The first and second patterns in your original command delineate line addresses, not intraline patterns. Totally different purpose.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
imanassypov
Tux's lil' helper
Tux's lil' helper


Joined: 08 Dec 2005
Posts: 118
Location: Toronto, Canada

PostPosted: Tue Nov 08, 2011 10:47 pm    Post subject: Reply with quote

-awesome,

thanks for you help guys!
_________________
I.M.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum