Reputation: 2996
From what I read about sed, multiple instructions within braces should work.
The second sed command works fine.
But why would the first sed command below fail?
echo "-------"
sed -e '/UNCOMMENT THIS/,/jmx/ { \
/foo/d \
/test/d \
}' \
test.txt
echo "-------"
sed -e '/UNCOMMENT THIS/,/jmx/ { /foo/d; /test/d }' \
test.txt
echo "-------"
Test.txt
<!-- To enable authentication security checks, uncomment the following security domain name -->
<!--UNCOMMENT THIS
foo
test
<property name="securityDomain">jmx-console</property>
-->
Upvotes: 0
Views: 1646
Reputation: 476528
Between single quotes ('
) the backslashes are interpreted as "real backslashes", so the escape characters are not interpreted".
You can resolve this by simply using a new line without the backslash in the quote environment:
sed -e '/UNCOMMENT THIS/,/jmx/ {
/foo/d
/test/d
}' \
test.txt
As you see, you need to provide a backslash at the end of the command, to ensure test.txt
is grouped with the command call. But bash
automatically groups content between two single quotes.
Upvotes: 1