0

I am trying to remove a string from a grep search, and I can't seem to get sed to work, despite the regex appearing to be correct. I am also using OSX, but I installed gnu-sed to make things a little easier.

I was hoping the following regex would remove all min certainties from :

gsed -r 's/minCertainty=\"\d\.\d{1,}\"//g'

Here is an example of the text I am dealing with, for context:

<vendor="company1" minCertainty="1.0"/>
<vendor="company2" minCertainty="0.75"/>
<vendor="company3" minCertainty="0.25"/>
Cyrus
  • 84,225
  • 14
  • 89
  • 153
jeff_h
  • 519
  • 1
  • 9
  • 26

2 Answers2

3

\d for digits is a perl extension to the standard regex syntax (either the basic or extended version). gsed -r uses the extended regex syntax, and doesn't include perl extensions. So use [0-9] or [[:digit:]] instead. Also, you don't need to escape the single-quotes in the expression (it doesn't seem to hurt, but I'd recommend against it). So use one of these:

gsed -r 's/minCertainty="[0-9]\.[0-9]{1,}"//g'
gsed -r 's/minCertainty="[[:digit:]]\.[[:digit:]]{1,}"//g'
Gordon Davisson
  • 118,432
  • 16
  • 123
  • 151
2

On my machine, gsed doesn't seem to support \d to detect digits—at least, it's not working here when I try it. The following regex works:

gsed -r 's/minCertainty=\"[0-9]\.[0-9]{1,}\"//g'

Charles Srstka
  • 16,665
  • 3
  • 34
  • 60