2

I am using OS X 10.10.5 and when I tried the following commands:

$ ls foo*
foo123bar.pdf
$ for f in foo*; do echo "$f" | sed -E 's:foo:bar:';done
bar123bar.pdf
$ for f in foo*; do echo "$f" | sed -E 's:foo:(&):';done
(foo)123bar.pdf
$ for f in foo*; do echo "$f" | sed -E 's:\(foo\):(\1):';done
sed: 1: "s:foo:(\1):": \1 not defined in the RE

I got an error.

My question is: how to remedy the error yielded by the last command above?

0

1 Answer 1

8

Under -E, you need to use unquoted parentheses to create a capture group.

sed -E 's:(foo):(\1):'
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.