View previous topic :: View next topic |
Author |
Message |
imanassypov Tux's lil' helper
Joined: 08 Dec 2005 Posts: 118 Location: Toronto, Canada
|
Posted: Tue Nov 08, 2011 4:09 pm Post subject: [SOLVED] sed - delete substring between two matches? |
|
|
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 |
|
|
tomk Bodhisattva
Joined: 23 Sep 2003 Posts: 7221 Location: Sat in front of my computer
|
Posted: Tue Nov 08, 2011 4:19 pm Post subject: |
|
|
Something like this:
Code: | sed -i -e "s/MARK1.*MARK2//g" filename |
_________________ Search | Read | Answer | Report | Strip |
|
Back to top |
|
|
imanassypov Tux's lil' helper
Joined: 08 Dec 2005 Posts: 118 Location: Toronto, Canada
|
Posted: Tue Nov 08, 2011 8:13 pm Post subject: |
|
|
Thanks, that works!
-whats the reason the command I tried did not work? _________________ I.M. |
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10589 Location: Somewhere over Atlanta, Georgia
|
Posted: Tue Nov 08, 2011 8:18 pm Post subject: |
|
|
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 |
|
|
imanassypov Tux's lil' helper
Joined: 08 Dec 2005 Posts: 118 Location: Toronto, Canada
|
Posted: Tue Nov 08, 2011 10:47 pm Post subject: |
|
|
-awesome,
thanks for you help guys! _________________ I.M. |
|
Back to top |
|
|
|