sed: delete text between a string until first occurrence of another string
- by Marit Hoen
Imagine I have something like the following text:
The quick brown fox jumps in 2012 and 2013
And I would wish to delete the part from "fox" including the four numbers but only in the first occurrence so I end up with:
The quick brown and 2013
Something likes this...:
echo "The quick brown fox jumps in 2012 and 2013" \
| sed "s/fox.*\([0-9]\{4\}\)//g"
...brings me:
The quick brown
So it removed everything including the last occurrence of the four numbers.
Any ideas?