0

I have the below string

sec.val.hos.patn=.*app\.com$|localhost$|127\.0\.0\.1$

I want replace .*app\.com$|localhost$|127\.0\.0\.1$ with * so that final string looks like below

sec.val.hos.patn=*

I am trying to solve this problem using below sed command on Mac OS

sed -i ' ' 's~\.\*app\\\.com\$\|localhost\$\|127\\\.0\\\.0\\\.1\$~\*~g' file.txt

but unable to get the desired replacement. Can someone please help me to get this working.

bbajagain
  • 1
  • 1

1 Answers1

0

I don't know if the pattern is actually more complex than you sample, but seems this should do the trick:

sed 's/\(^.*=\).*$/\1*/' <<< "sec.val.hos.patn=.*app\.com$|localhost$|127\.0\.0\.1$"

Here we capture everything from the start to =, then we replace the whole thing with capture group 1 plus *.

theherk
  • 6,954
  • 3
  • 27
  • 52