sed - Replace nth regex issue -


if want remove first period , behind string, in sed can e.g. do:

echo 2.6.0.3-8 | sed 's/\..*//' 

output:

2 

but if want remove second period , behind it, think should able (gnu sed):

echo 2.6.0.3-8 | sed 's/\..*//2g' 

however output is:

2.6.0.3-8    

from manual:

'number' replace numberth match of regexp.

what have missed here?

you're there getting burned .* , greediness. have specific case replace .* [^.]*:

 $ echo 2.6.0.3-8 | sed 's/\.[^.]*//2g' 2.6 $ echo 2.6.0.3-8 | sed 's/\.[^.]*//3g' 2.6.0 $ echo 2.6.0.3-8 | sed 's/\.[^.]*//1g' 2 

[^.] means characters aren't dot.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -