sed: delete text between a string until first occurrence of another string
Posted
by
Marit Hoen
on Super User
See other posts from Super User
or by Marit Hoen
Published on 2012-09-06T16:04:05Z
Indexed on
2012/09/07
3:40 UTC
Read the original article
Hit count: 621
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?
© Super User or respective owner