Issue
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 ................"
Solution
I suggest with GNU sed:
sed -E 's/([^.])\.\.([^.])/\1.PUBLIC.\2/'
See: The Stack Overflow Regular Expressions FAQ
Answered By - Cyrus Answer Checked By - Clifford M. (WPSolving Volunteer)