-1

I am new to SED but learning fast. I am trying to replace 2 consecutive dots in a string with another string. The string should only 2 consecutive dots. The string is a qualified table name. The string is:

INNER JOIN DbName..TableName with (nolock)  -- comment with lots of dots ................

In the string only DbName..TableName should be replaced by DbName.PUBLIC.TableName I tried using SED with the pattern:

sed s:\(.*\[a-zA-Z0-9\]\+\)\.\.(\[a-zA-Z0-9]\*):\1.PUBLIC.\2:gi

I thought this pattern would work but when I try it the same string is returned. I entered:

echo "INNER JOIN DbName..TableName with (nolock)  -- comment with lots of dots ................" | sed s:\(.*\[a-zA-Z0-9\]\+\)\.\.\(\[a-zA-Z0-9]\*\):\1.PUBLIC.\2:gi

The output from the command was the echo string. What am I doing wrong?

echo "INNER JOIN DbName..TableName with (nolock)  -- comment with lots of dots ................" | sed  s:\(.*\[a-zA-Z0-9\]\+\)\.\.\(\[a-zA-Z0-9]\*\):\1.PUBLIC.\2:gi

I was expecting:

INNER JOIN DbName.PUBLIC.TableName with (nolock)  -- comment with lots of dots ................"
Barmar
  • 741,623
  • 53
  • 500
  • 612
GordyCA
  • 71
  • 2
  • 6

2 Answers2

1

I suggest with GNU sed:

sed -E 's/([^.])\.\.([^.])/\1.PUBLIC.\2/'

See: The Stack Overflow Regular Expressions FAQ

Cyrus
  • 84,225
  • 14
  • 89
  • 153
0

Put the sed argument inside quotes, otherwise \. becomes simply . when the shell processes the escape sequence.

sed 's/\.\./.PUBLIC./g'
Barmar
  • 741,623
  • 53
  • 500
  • 612