0

In the following example I am looking to include the * metacharacter in the string replacement. If I understand correctly, I should be able to escape the character using \ but after doing that this is the result I am seeing:

❯ echo 'foo(*)' | sed s/foo\(\*/bar/g
bar*)

I was expecting to see the following:

❯ echo 'foo(*)' | sed s/foo\(\*/bar/g
bar)
Jack Rowlingson
  • 325
  • 2
  • 9

1 Answers1

2

You need to quote your sed command:

echo 'foo(*)' | sed 's/foo(\*/bar/g'
bar)
oliv
  • 12,690
  • 25
  • 45