I’m facing an interesting issue with a regexp, i’m using this within a small sed script (bash),
here it is:
cities="new york;milan;rome;paris;london"
echo ${cities} | sed 's/new.*;//'
This prints: London
Basically the script substitutes everything until the last semicolon occurrence, while what i want is to simply delete whats matched by (new.*) until the first occurrence of the semicolon
Any advice?
You need to do a non-greedy substitution:
This doesn’t work if your data strings do not end with a semi-colon. In that case you could do something like this:
Edit
As noted by Ed in the comments, the second solution does not preserve empty fields. If that is needed this works (as far as I’ve tested it):